简体   繁体   中英

Javascript convert from UTC to local date time

I am getting a datetime that is in UTC. I like the result to show the datetime locally in the following format:

    September 18th 2013, 7:07:00 PM

Is there a function that can come close to this..

I tried the following but not the result I was looking for:

     var dt = new Date(date + " UTC");
     return dt.toString(); 

Different variations of this question have been asked many times before. Without knowing your input datatype for "date" the question is a little unclear. Please refer to this post, it should answer your question on formatting dates.

Where can I find documentation on formatting a date in JavaScript?

您可以为此使用moment.js

moment().format('LLL');  // Closest output will be like this :- October 9 2013 11:17 PM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM