search

Home  >  Q&A  >  body text

About javascript time object

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

给我你的怀抱给我你的怀抱2775 days ago710

reply all(3)I'll reply

  • 黄舟

    黄舟2017-05-19 10:28:57

    new Date().toISOString();

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

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:28:57

    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构造函数获得本地时间对象

    reply
    0
  • PHPz

    PHPz2017-05-19 10:28:57

    new Date().toISOString();

    reply
    0
  • Cancelreply