TIME Format Issue in AngularJS - angularjs

When i am posting date and time .. the date is Okay but the time appeared Like this
: Thu Jan 01 1970 12:59:00 GMT+0200 (Eastern European Standard Time)
And when i checked the DB it was :
In DB ( Time Not the same Because of the Eastern European Standard Time

Related

I have facing issue with date in angularjs, when I use central timezone(-6,-7,-8) getting issue with date

I have this date in startdate=2021-10-27T00:00:00-04:00,
d=new Date(data.StartDate) // outputTue Oct 26 2021 23:00:00 GMT-0500
But date is getting one day before'Tue Oct 26 2021 23:00:00 GMT-0500' in central timezone(below -6,-7,-8...),
How to resolve this date issue(26) in central timezone and for all timezones it is getting well. But only -6,-7... timezone have an issue

Fri May 29 2020 06:35:59 GMT+0530 (India Standard Time) i want India Standard Time as IST in react js

i want to get timezone name like India Standard Time as IST from Fri May 29 2020 06:35:59 GMT+0530 (India Standard Time)
moment().tz('Asia/Colombo').format('MMMM Do YYYY, h:mm:ss a Z[(IST)]');
You can format IST using moment JS timezones. https://momentjs.com/timezone/docs/

Moment returns wrong datetime

I am using React as a front-end framework, python as a back-end language.
Python returns UTC datetime to React. Somehow, react+moment shows wrong local datetime (Berlin timezone). May I know, what to fix this issue ?
Case 1 is correct, but case 2 is wrong
Case 1:
Python returns to React: "2019-10-02T22:00:00Z"
React+Moment returns: Thu Oct 03 2019 00:00:00 GMT+0200 (Central European Summer Time) {}
moment('2019-10-02T22:00:00Z').toDate()
Thu Oct 03 2019 00:00:00 GMT+0200 (Central European Summer Time)
Case 2:
Python returns to React: "2019-10-30T22:00:00Z"
React+Moment returns: Wed Oct 30 2019 23:00:00 GMT+0100 (Central European Standard Time) {}
moment('2019-10-30T22:00:00Z').toDate()
Wed Oct 30 2019 23:00:00 GMT+0100 (Central European Standard Time)
Python is using utc while moment.js is using an extra offset of +1 or whatever (your local time). If you want moment.js to use utc too, do this:
const m = moment.utc('2019-10-30T22:00:00Z')
console.log(m.toDate())

Time conversion to IST

I'm trying to convert date & time stamp to IST using Moment. I tried following
moment(1369266934311).utcOffset("+05:30").format() I'm getting output as 2017-12-05T00:00:00+05:30.
But my required format is Tue Dec 05 2017 00:00:00 GMT+0530 (India Standard Time).
Get the date object from the moment object and call its .toString() method.
moment(1369266934311).utcOffset("+05:30").toDate().toString();
// => "Thu May 23 2013 05:25:34 GMT+0530 (IST)"
And, by the way, 1369266934311 is a different date from what you mentioned in your question.

moment to date object timezone issue

I have a moment.js object generated from fullcalendar in BST that looks like this:
console.log(momentSelected)
//Moment {_isAMomentObject: true, _isUTC: true, _offset: 0, _locale: f, _d: Tue May 03 2016 01:00:00 GMT+0100 (BST)…}
I don't want a BST time but a UTC time that looks like this:
console.log(momentSelected.format('YYYY-MM-DD HH:mm Z'));
//2016-05-03 00:00 +00:00
Now I need to convert it into a Date object:
$scope.date = new Date(momentSelected.format('YYYY-MM-DD HH:mm Z'));
console.log($scope.date);
//Wed May 04 2016 01:00:00 GMT+0100 (BST)
The last output is wrong... I want Wed May 04 2016 00:00:00+00:00 (UTC)
You can create a Date object using the toDate function on the moment object.
$scope.date = momentSelected.toDate();
However, you must recognize that the nature of the Date object is that it will always represent UTC internally, and its toString function will always reflect the local time zone where the code is running.
If your local time zone is UK (alternating between GMT and BST for daylight saving time), then it is impossible to get (UTC) time in the string produced by console.log($scope.date);, regardless of how you created that date.
This is why it is better to use moment's format function and display that string directly. A moment can reflect UTC, local time, and other time zones. A Date object cannot.
Also, you should pay no attention to the underscore-prefixed internal fields of a moment object. Use the public API instead. See the moment user guide.

Resources