locked
where does the new Date() get its formate? RRS feed

  • Question

  • User2102072086 posted

    hi,

        when i type new Date() it shows 

    Thu Aug 27 2020 14:00:00 GMT+1400 (Line Islands Time)

    I want to know where does it get the above formte?

    Wednesday, August 26, 2020 12:20 PM

Answers

All replies

  • User475983607 posted

        when i type new Date() it shows 

    Thu Aug 27 2020 14:00:00 GMT+1400 (Line Islands Time)

    I want to know where does it get the above formte?

    When you first get a new PC and turn it on, the setup program asks a bunch of questions like your timezone, preferred language, local etc.  This is were the format originates.  The actual format on the screen is simply how JavaScript displays a default date depending on the OS configuration.

    Language reference

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

    Wednesday, August 26, 2020 12:51 PM
  • User-474980206 posted

    Here is the spec

    https://tc39.es/ecma402/#datetimeformat-objects

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2020 3:00 PM
  • User2102072086 posted

    NO the formate is not affected by computer settings,

    it only picks the date time zone form computer.

    for ex I changed the log formate in the computer Thu 27 Aug 2020 but it did not change.

    somebody writes "new Date() produces an object, a new instance of the Date JavaScript class. It contains the current date and time stored in some internal format (read the documentation for details)."

    Thursday, August 27, 2020 3:10 AM
  • User303363814 posted

    A javascript Date does not have a format.  From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date 

    Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.

    So, a Date is a number, normally stored in binary.  There is no format.  Have a look at the .valueOf() method which returns the primitive value.  A few moments ago new Date().valueOf() returned 1598499382572.

    If you convert the Date to a string then you can take control of the formatiing in a number of ways.  Check out the documentation at the reference above.

    Thursday, August 27, 2020 3:38 AM
  • User475983607 posted

    NO the formate is not affected by computer settings,

    it only picks the date time zone form computer.

    for ex I changed the log formate in the computer Thu 27 Aug 2020 but it did not change.

    somebody writes "new Date() produces an object, a new instance of the Date JavaScript class. It contains the current date and time stored in some internal format (read the documentation for details)."

    You misunderstand my post.  JavaScript gets the date from the system clock.  The system click is based on the local and timezone.

    Thursday, August 27, 2020 10:48 AM
  • User753101303 posted

    Hi,

    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString (in  short this is a now a specification though you could have another string with older browsers)

    Make sure to make the difference between the actual value stored and how it is shown when you are trying to observe this value.

    Maybe ask a more direct question. Are you trying to show this value according to some country convention? For example you have https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat (which shows the same value depending on distinct country convention).

    Thursday, August 27, 2020 1:26 PM
  • User-474980206 posted

    rajemessage

    NO the formate is not affected by computer settings,

    it only picks the date time zone form computer.

    for ex I changed the log formate in the computer Thu 27 Aug 2020 but it did not change.

    somebody writes "new Date() produces an object, a new instance of the Date JavaScript class. It contains the current date and time stored in some internal format (read the documentation for details)."


    javascript uses the browser culture which effects the spelling of the months and days of week.This may not match the o/s

    Thursday, August 27, 2020 8:25 PM