Last active
August 29, 2015 14:03
-
-
Save janbiasi/d9cae90d29b1b4fb6285 to your computer and use it in GitHub Desktop.
Creating timestamps in JavaScript
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
/** | |
* 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; | |
}; |
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
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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you are so hotttt i want fuck you