I am using luxon to convert the date:
console.log(DateTime.now('Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time)').toISODate())
Now i get: 2022-04-07. But this is today's day, but i need to get this format from this: Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time). How to get this using luxon library?
Try using console.log(DateTime.local('Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time)').toISODate()).
By using DateTime.now(etc...), it automatically returns the current date.
Related
I want to ask a question. Can we insert current Time in old Date?
Like this is a old date "Fri Nov 19 2021 00:00:00 GMT+0500 (Pakistan Standard Time)" and I want to convert it to something like this "Fri Nov 19 2021 (current Time right now) GMT+0500 (Pakistan Standard Time)".
Thanks in advance.
You can try using the setHours method, as in the following example:
const saveTime = new Date();
console.log(saveTime);
Tue Nov 23 2021 06:24:29 GMT-0500 (Cuba Standard Time)
saveTime.setHours(20,35,43)
console.log(saveTime);
Tue Nov 23 2021 20:35:43 GMT-0500 (Cuba Standard Time)
I have an array of dates which returns:
[Mon Aug 03 2020 00:00:00 GMT+0100 (British Summer Time), Wed Aug 05 2020 00:00:00 GMT+0100 (British Summer Time)]
I need to convert these into a format as such
["2020-02-13T02:39:51.054", "2020-02-13T02:39:51.054"]
Using a function which would be the best way to do this?
I was unable to recreate problem in stack blitz as the dates in stackblitz by default are in my desired format but the project I am working on requires dates in the first format. I only need to change format in one array instance.
Use the DatePipe.
let x = ['Mon Aug 03 2020 00:00:00 GMT+0100 (British Summer Time)', 'Wed Aug 05 2020 00:00:00 GMT+0100 (British Summer Time)'];
let a = x.map(a=>this.datePipe.transform(a, 'YYYY-MM-DDTHH:mm:ss.SSS'));
console.log(a);
This question already has answers here:
Browsers, time zones, Chrome 67 Error (historic timezone changes)
(2 answers)
Closed 4 years ago.
I have an application which allows users to pick some time slots. By default the timeslots are empty, and my .NET back-end has default generated values of type DateTimeOffset, which by default are set to "0001-01-01T00:00:00+00:00".
Now, when I populate a date on the front-end with this value, it generates a date in the local time zone, but with wrong minutes and seconds. This happens only in Chrome. I'm not seeing this under Edge or Firefox.
console.log(new Date("2001-01-01T00:00:00+00:00").toString())
// Mon Jan 01 2001 02:00:00 GMT+0200 (Eastern European Standard Time)
console.log(new Date("1001-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1001 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1801-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1801 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1901-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1901 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1961-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1961 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1921-01-01T00:00:00+00:00").toString())
//Sat Jan 01 1921 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1931-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1931 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1922-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1922 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1923-01-01T00:00:00+00:00").toString())
//Mon Jan 01 1923 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1924-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1924 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1925-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1925 02:00:00 GMT+0200 (Eastern European Standard Time)
As you can see, I played around with the date, to see before which date this happens, but the problem may not be the year 1925, just certain time before the current date. Does anyone know why this is happening?
Screenshot as requested
Prior to 1883 Time Zones were not standardized. If you check every year you'll notice that 1883 is "broken" with the additional minutes and 1884 is "fine". Chrome handles this transition very well - you'll notice the "problem" doesn't exist in Firefox.
new Date("1883-01-01T00:00:00+00:00")
Sun Dec 31 1882 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1884-01-01T00:00:00+00:00")
Mon Dec 31 1883 16:00:00 GMT-0800 (Pacific Standard Time)
In fact, you can track this down to November 18th, 1883.
new Date("1883-11-18T00:00:00+00:00")
Sat Nov 17 1883 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1883-11-19T00:00:00+00:00")
Sun Nov 18 1883 16:00:00 GMT-0800 (Pacific Standard Time)
Chrome tries very hard to match time, even going so far as to calculate the suspended DST of Ramadan in Egypt in 2010.
Read more here: https://www.huffingtonpost.com/quora/how-when-and-why-were-tim_b_5838042.html
I have these date objects. I want to bundle them all together and send it across via ajax to backend.
$scope.date1 = Fri Feb 12 2016 12:14:20 GMT-0800 (Pacific Standard Time)
$scope.date2 = Sat Feb 13 2016 12:14:20 GMT-0800 (Pacific Standard Time)
$scope.date3 = Sun Feb 14 2016 12:14:20 GMT-0800 (Pacific Standard Time)
$scope.date4 = Mon Feb 15 2016 12:14:20 GMT-0800 (Pacific Standard Time)
Can someone tell me a way how to do it.
An array.
$scope.dates = [$scope.date1, $scope.date2, $scope.date3, $scope.date4];
If you ever find yourself numbering variables, that's a red flag that you should be using an array.
Can someone explain me the output http://jsfiddle.net/mark69_fnd/NhuLe/ produces?
new Date('2012-07-01') == Sat Jun 30 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-07-09') == Sun Jul 08 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-07-10') == Mon Jul 09 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-07-31') == Mon Jul 30 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-08-1') == Wed Aug 01 2012 00:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-08-9') == Thu Aug 09 2012 00:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-08-10') == Thu Aug 09 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-08-31') == Thu Aug 30 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-09-1') == Sat Sep 01 2012 00:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-09-9') == Sun Sep 09 2012 00:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-09-10') == Sun Sep 09 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2012-12-09') == Sat Dec 08 2012 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2012-12-31') == Sun Dec 30 2012 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2013-01-01') == Mon Dec 31 2012 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2013-01-09') == Tue Jan 08 2013 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2013-02-09') == Fri Feb 08 2013 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2013-03-09') == Fri Mar 08 2013 19:00:00 GMT-0500 (Eastern Standard Time)
new Date('2013-04-09') == Mon Apr 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2013-05-09') == Wed May 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2013-06-09') == Sat Jun 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2013-07-09') == Mon Jul 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2013-08-09') == Thu Aug 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
new Date('2013-09-09') == Sun Sep 08 2013 20:00:00 GMT-0400 (Eastern Daylight Time)
I am interested to understand how it decides to compute the day. Please, note the difference between 2012-07-09, 2012-08-9 and 2013-08-09.
I ran it on Chrome.
This is a very interesting, and subtle, question.
The reason is that some of your dates are in the ISO-8601-like format defined in the specification, and so are parsed as GMT, but others are not, and so they fall back on non-standard date parsing, which appears to be (in Chrome) using local time instead.
The date string 2012-07-01 conforms to the format specified in Section 15.9.1.15, and so according to the rules of that section, it is parsed in timezone Z (GMT). Then you output it and it's output in local time, four hours or so earlier, and so the date changes as the original value (having no time part) is at midnight.
The date string 2012-08-1 does not conform to that format (it needs a 0 before the 1). This takes us out of the land of specified behavior. The Date constructor, when given a string, follows the same rules as Date.parse, which are defined in Section 15.9.4.2, which says amongst other things:
The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.
(My emphasis)
The moral of this story is: Stick to specified formats. :-)
But a side note on that: The date/time format defined in the spec is relatively new (as of ES5, about three years ago). Prior to that, there was no defined date/time format that the Date constructor (or Date parse) was required to parse. It just had to be able to parse whatever Date#toString spat out, but what that was was implementation-specific. And older browsers will indeed fail to parse 2012-08-01. Although it's not specified, nearly all browsers (every one I've ever tested) will parse 2012/08/01, though. Of course, now I want to go back and see what time zone they use (and check whether they all use the same one)...
new Date('2012-07-01') means that you are providing date in *GMT 000*0 timezone.
But when it displays you the date it does the same in your browser timezone(which is GMT -400 in your case).
Thats is the reason that you see all the timings to be 20:00.