Home While converting UTC date to local date giving wrong time
Reply: 1

While converting UTC date to local date giving wrong time

ramakrishna nerella
1#
ramakrishna nerella Published in 2017-12-07 14:38:30Z

I have UTC date /Date(1512624687600)/

I want to convert it into local time but its giving me 2017-12-07 09:31 PM Indian Standard Time etc. I had tried different types to get solution (local time). Please find my code below:

$scope.UtcToLocal = function(utcTime){
var milli = parseInt(utcTime.replace(/\/Date\((-?\d+)\)\//, '$1')); 
alert(milli);

var fromDate = moment(utcTime).format("YYYY-MM-DD hh:mm A");
alert(fromDate);

var gmtDateTime = moment.utc(fromDate, "YYYY-MM-DD h:mm A");
alert(gmtDateTime);

var local = gmtDateTime.local().format('YYYY-MMM-DD h:mm A');
return local;

I am using Moment.js code to demonstrate the above codes.

Aamir Ali
2#
Aamir Ali Reply to 2017-12-07 17:16:49Z

UTC date time always give universal time of your region. most probably it will give you 4 hours later or earlier time. If you want get local time, then you need to use DateTime.Now in case of asp.net mvc

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342509 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO