About javascript time object
给我你的怀抱
给我你的怀抱 2017-05-19 10:26:57
0
3
689

The problem is this. The company wants to make an online video tutorial, which requires students to make an appointment and the teacher to get the time to start the class. However, because it is international, the time in each time zone is different, so the front end needs to convert the time into UTC time. Send it to the backend, and then convert the UTC time into local time when getting the data. Please help, how can js realize the conversion between local time and UTC time

给我你的怀抱
给我你的怀抱

reply all(3)
黄舟
new Date().toISOString();

At the same time, the Date object also accepts parameters to convert the corresponding parameters into utc

迷茫

Local To UTC

var localDateTime = new Date();   

var utcDateTime = localDateTime.toISOString();  
console.log(utcDateTime);   //"2017-04-27T17:56:34.601Z"

UTC to Local

var utcDateTimeStr = "2017-04-27T17:56:34.601Z";
var localDateTime = new Date(utcDateTimeStr);  // 使用Date构造函数获得本地时间对象
PHPzhong

new Date().toISOString();

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!