Skip to content

Instantly share code, notes, and snippets.

@janbiasi
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbiasi/d9cae90d29b1b4fb6285 to your computer and use it in GitHub Desktop.
Save janbiasi/d9cae90d29b1b4fb6285 to your computer and use it in GitHub Desktop.
Creating timestamps in JavaScript
/**
* Generate a datestamp in your format
* @return {string} datestamp
*/
function datestamp(seperator) {
var today = new Date(), dd = today.getDate(), mm = today.getMonth() + 1, yyyy = today.getFullYear();
seperator = seperator != null && seperator.length > 0 ? seperator : "/";
dd = dd < 10 ? '0' + dd : dd;
mm = mm < 10 ? '0' + mm : mm;
return dd + seperator + mm + seperator + yyyy;
}
/**
* Generate a timestamp in your format
* @return {string} timestamp
*/
function timestamp() {
var cDate = new Date(),
dd = cDate.getDate(),
mm = cDate.getMonth() + 1,
yyyy = cDate.getFullYear(),
hh = cDate.getHours(),
ms = cDate.getMinutes(),
ss = cDate.getSeconds();
if(dd < 10) dd = '0' + dd;
if(mm < 10) mm = '0' + mm;
if(hh < 10) hh = "0" + hh;
if(ms < 10) ms = "0" + ms;
if(ss < 10) ss = "0" + ss;
return dd + '.' + mm + '.' + yyyy + " " + hh + ":" + ms + ":" + ss;
};
var ds = datestamp("/"); // 30/07/2014
var ts = timestamp(); // 30.07.2014 14:19:07
// Change the format in the `timestamp()`
// method to whatever you want!
@nuttesohn
Copy link

you are so hotttt i want fuck you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment