Posted By

madr on 04/15/11


Tagged

javascript date textmate


Versions (?)

Generate readable date function, with optional date diff


 / Published in: Other
 

  1. function adate(daysFromNow) {
  2. var date, datestr, mm, dd;
  3.  
  4. datestr = new Date().getTime();
  5.  
  6. if (!!daysFromNow) {
  7. datestr += (1000 * 60 * 60 * 24 * daysFromNow);
  8. }
  9.  
  10. date = new Date(datestr);
  11.  
  12. mm = date.getMonth() + '';
  13. if (mm.length == 1) {
  14. mm = '0' + mm;
  15. }
  16.  
  17. dd = date.getDate() + '';
  18. if (dd.length == 1) {
  19. dd = '0' + dd;
  20. }
  21.  
  22. return date.getFullYear() + '-' +
  23. mm + '-' + dd;
  24. }

Report this snippet  

You need to login to post a comment.