📌  相关文章
📜  如何使用 JavaScript 将 UTC 日期时间转换为本地日期时间?

📅  最后修改于: 2021-08-31 07:24:28             🧑  作者: Mango

给定一个 UTC 日期,任务是使用 JavaScript toLocaleString()函数将 UTC 日期时间转换为本地日期时间。

句法:

var theDate = new Date(Date.parse('06/14/2020 4:41:48 PM UTC'))
theDate.toLocaleString()

JavaScript 代码:

// Funcion to convert UTC date-time
// to Local date-time
function myFunction() {
    var theDate = new Date(Date.parse(
            '06/14/2020 4:41:48 PM UTC'));
  
    document.write("Local date Time: ", 
            theDate.toLocaleString());
}

示例:此示例使用 JavaScript 将 UTC 日期时间转换为本地日期时间。



  

    
        How to convert UTC date time
        into local date time?
    
  
    

  

    

GeekforGeeks

       

        Click the button to convert         UTC date and time to local         date and time     

       

        UTC date and time:         06/14/2020 4:41:48 PM     

               

          

输出:

  • 点击按钮前:
  • 点击按钮后: