User Tools

Site Tools


javascript:date_object_to_yyyymmdd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
javascript:date_object_to_yyyymmdd [2016/07/07 19:24] peterjavascript:date_object_to_yyyymmdd [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 70: Line 70:
  
  
 +===== Using Date.toISOString() =====
  
-This is single line of code that you can use to create a YYYY-MM-DD string of today's date.+**WARNING**:  **Date.toISOString()** creates UTC formatted date and hence can jump date boundaries depending on the timezone. E.g. in GMT+1: (new Date(2013,13, 25)).toISOString() == '2013-12-24T23:00:00.000Z'  
 + 
 +To create a **YYYY-MM-DD** string of today's date:
  
 <code javascript> <code javascript>
Line 79: Line 82:
  
 or or
- 
-didn't like adding to the prototype. An alternative would be: 
  
 <code javascript> <code javascript>
Line 86: Line 87:
 var res = d.toISOString().slice(0,10).replace(/-/g,""); var res = d.toISOString().slice(0,10).replace(/-/g,"");
 </code> </code>
 +
 +
 +To get **YYYYMMDDHHmmSSsss**use this: 
 +
 +<code javascript>
 +var ds = (new Date()).toISOString().replace(/[^0-9]/g, "");
 +</code>
 +
  
javascript/date_object_to_yyyymmdd.1467919446.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki