Created
March 18, 2011 22:40
-
-
Save pec1985/876981 to your computer and use it in GitHub Desktop.
date in UTC and Current
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function utcDate(e){ | |
var day = e.getUTCDate(); | |
var month = e.getUTCMonth()+1; | |
var year = e.getUTCFullYear(); | |
var hour = e.getUTCHours(); | |
var minutes = e.getUTCMinutes(); | |
var seconds = e.getUTCSeconds(); | |
if(month<10){month = '0'+month;} | |
if(day<10){day = '0'+day;} | |
if(hour<10){hour = '0'+hour;} | |
if(minutes<10){minutes = '0'+minutes;} | |
if(seconds<10){seconds = '0'+seconds;} | |
return (year+'-'+month+'-'+day+' '+hour+':'+minutes+':'+seconds+' +0000'); | |
} | |
function normalDate(e){ | |
var day = e.getDate(); | |
var month = e.getMonth()+1; | |
var year = e.getFullYear(); | |
var hour = e.getHours(); | |
var minutes = e.getMinutes(); | |
var seconds = e.getSeconds(); | |
if(month<10){month = '0'+month;} | |
if(day<10){day = '0'+day;} | |
if(hour<10){hour = '0'+hour;} | |
if(minutes<10){minutes = '0'+minutes;} | |
if(seconds<10){seconds = '0'+seconds;} | |
return (year+'-'+month+'-'+day+' '+hour+':'+minutes+':'+seconds+' +0000'); | |
} | |
alert(utcDate(new Date())); | |
alert(normalDate(new Date())); | |
var d = new Date(); | |
var month = (d.getMonth()+1).toLocaleString(); | |
var day = d.getDate().toLocaleString(); | |
var year = d.getFullYear().toLocaleString(); | |
alert( month +'/'+day +'/'+year); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment