Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created March 18, 2011 22:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pec1985/876981 to your computer and use it in GitHub Desktop.
Save pec1985/876981 to your computer and use it in GitHub Desktop.
date in UTC and Current
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