I'm trying to return a date function, from
Mon Jul 30 2012 10:57:56 GMT 0100 (GMT Daylight Time)
to
30 July 2012 10:57:56
Tried out most of the date functions, but still no answer/format.
Do not invent a bicycle, use library for this: http://blog.stevenlevithan.com/archives/date-time-format
Related
Very odd issue using momentjs:
moment().startOf('month').toDate() produces:
Sun Nov 01 2020 00:00:00 GMT-0400 (Eastern Daylight Time)
moment().endOf('month').toDate() produces:
Mon Nov 30 2020 23:59:59 GMT-0500 (Eastern Standard Time)
Why is there a change of timezone? Why does start choose EDT and the endOf chose EST?
startOf('month') and endOf('month') returns the first and last date of the month in the browser's timezone.
On November 1st, 2020, daylight savings time ended in the USA, so up to November 1st, your browser's timezone will be EDT (if you're in the Eastern Timezone area), and after November 1st, it will be EST.
If you want to get a specific timezone-based time, you can use moment-timezone.
1) My Accurate date is :Tue Apr 25 2019 00:00:00 GMT+0530
2) But in Calendar when i am selecting time i was get like this
Tue Apr 24 2019 16:56:00 GMT+0530
I was tried to fix below way
moment($scope.ProjectModel.projectStartDate).startOf('day')
But I am getting Tue Apr 24 2019 00:00:00 GMT+0530
This one is not correct, correct date: Tue Apr 25 2019 00:00:00 GMT+0530
So what i need to do to get this date ?
So, it seems like you want to set the date to the start of the next day, rather than the start of the current one. You can do it like this:
moment($scope.ProjectModel.projectStartDate).startOf('day').add(1, 'days');
Or, it seems like you want to round up if the provided date is noon or later, and down otherwise. In this case, just add 12 hours before going to the start of the day:
moment($scope.ProjectModel.projectStartDate).add(12, 'hours').startOf('day');
I have a database where I have put down timestamps that are converted to UTC.
Now, when I am on PST, I convert 2 timestamps in Chrome, which get back to the following dates:
new Date(1446274800000)
Sat Oct 31 2015 00:00:00 GMT-0700 (PDT)
new Date(1448265600000)
Mon Nov 23 2015 00:00:00 GMT-0800 (PST)
They differ in timezone! How is this possible? I always just want to get back the PST time (or, preferably, the UTC time they were stored in).
Looks like it's daylight savings time.
I need to convert a String to a Date object.
The date string is delivered in the following format:
"2015-01-28T00:00:00"
When I create a new Date, I get the previous date:
Entered: new Date("2015-01-28T00:00:00")
Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
Does anyone know why this is occurring?
When you enter the following:
new Date("2015-01-28T00:00:00");
// Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
the browser assumes that you are giving a date in GMT Time zone. So it will automatically convert the given date to your local date.
It's always a good idea to inform the browser of the timezone you are working on in order to prevent future problems:
new Date("2015-01-28T00:00:00-07:00");
// Result: Tue Jan 28 2015 00:00:00 GMT-0700 (Mountain Standard Time)
Actually, you aren't getting the previous date . . . you are getting that date, offset by the timezone difference.
Tue Jan 27 2015 17:00:00(Mountain Time) + 7 hours (time zone difference) = 2015-01-28T00:00:00 (GMT)
Or, in English, when it is 12:00 Midnight in Greenwich, England, it is 5:00 PM on the previous day in Denver, Colorado. ;)
It's the right date/time, just in a different timezone.
How can I display a date to behave like that day regardless of the users time-zone?
>>> new Date('2013-09-17')
Date {Mon Sep 16 2013 20:00:00 GMT-0400 (Eastern Standard Time)}
I'm trying to use the jquery datepicker formater, however when I pass the date object it's off by a day.
How can I make sure that the users timezone is disregarded?
OK, I split the string and passed them as parameters for my expected result.
>>> d = '2013-09-17'.split('-'); new Date(d[0],d[1]-1,d[2]);
Date {Thu Oct 17 2013 00:00:00 GMT-0400 (Eastern Standard Time)}