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.
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)."
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.
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.
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
Member
16 Points
172 Posts
where does the new Date() get its formate?
Aug 26, 2020 12:20 PM|rajemessage|LINK
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?
All-Star
52991 Points
23585 Posts
Re: where does the new Date() get its formate?
Aug 26, 2020 12:51 PM|mgebhard|LINK
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
All-Star
58144 Points
15646 Posts
Re: where does the new Date() get its formate?
Aug 26, 2020 03:00 PM|bruce (sqlwork.com)|LINK
Here is the spec
https://tc39.es/ecma402/#datetimeformat-objects
Member
16 Points
172 Posts
Re: where does the new Date() get its formate?
Aug 27, 2020 03:10 AM|rajemessage|LINK
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 theDate
JavaScript class. It contains the current date and time stored in some internal format (read the documentation for details)."Participant
1620 Points
927 Posts
Re: where does the new Date() get its formate?
Aug 27, 2020 03:38 AM|PaulTheSmith|LINK
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 aNumber
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.
All-Star
52991 Points
23585 Posts
Re: where does the new Date() get its formate?
Aug 27, 2020 10:48 AM|mgebhard|LINK
You misunderstand my post. JavaScript gets the date from the system clock. The system click is based on the local and timezone.
All-Star
48490 Points
18071 Posts
Re: where does the new Date() get its formate?
Aug 27, 2020 01:26 PM|PatriceSc|LINK
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).
All-Star
58144 Points
15646 Posts
Re: where does the new Date() get its formate?
Aug 27, 2020 08:25 PM|bruce (sqlwork.com)|LINK
javascript uses the browser culture which effects the spelling of the months and days of week.This may not match the o/s