Convert UTC date time to local date time

前端 未结 30 1208
悲哀的现实
悲哀的现实 2020-11-22 01:09

From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM and it is in UTC time. I want to convert it to the current user’s browser time us

30条回答
  •  臣服心动
    2020-11-22 01:28

    You can use momentjs ,moment(date).format() will always give result in local date.

    Bonus , you can format in any way you want. For eg.

    moment().format('MMMM Do YYYY, h:mm:ss a'); // September 14th 2018, 12:51:03 pm
    moment().format('ffffdd');                    // Friday
    moment().format("MMM Do YY"); 
    

    For more details you can refer Moment js website

提交回复
热议问题