Skip to content

Instantly share code, notes, and snippets.

@wolf432
Created November 9, 2016 03:24
Show Gist options
  • Save wolf432/da3f67d218d5055f56efd3a6233b5fc6 to your computer and use it in GitHub Desktop.
Save wolf432/da3f67d218d5055f56efd3a6233b5fc6 to your computer and use it in GitHub Desktop.
JS获取当前世界
function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds(); //秒
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm + ":";
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment