简体   繁体   English

无法理解此代码[JavaScript,日期和获取时区]

[英]Unable to understand this code [JavaScript , Dates and Obtaining TimeZones]

Please help me to understand this code :- 请帮助我理解此代码:

function seconds_with_leading_zeros(dt)   
{   
  return /\((.*)\)/.exec(new Date().toString())[1];  
}  

dt = new Date();   
console.log(seconds_with_leading_zeros(dt));   

dt = new Date(1989, 10, 1);   
console.log(seconds_with_leading_zeros(dt)); 

It is suppose to show user's time zone. 假设显示用户的时区。

new Date().toString() returns a string like "Wed Mar 29 2017 15:37:26 GMT+0200 (West-Europa (zomertijd))" The timezone is inside the round brackets (). new Date().toString()返回一个字符串,例如"Wed Mar 29 2017 15:37:26 GMT+0200 (West-Europa (zomertijd))"时区位于圆括号()中。

return /\\((.*)\\)/.exec("date and time (timezone)")[1]; returns whatever is inside the brackets. 返回括号内的内容。 In this case it will return the word "timezone" 在这种情况下,它将返回单词"timezone"

That's as good as i can explain it :) 就像我能解释的那样:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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