actionscript - date object


/ Published in: ActionScript
Save to your folder(s)

actionscript date object and some date calculations


Copy this code and paste it in your HTML
  1. // create variable dateNow with the current date
  2. var dateNow = new Date();
  3.  
  4. // create variable with specified date
  5. var dateBirthday = new Date(1987,2,22);
  6.  
  7. // create variable with date from number
  8. var dateFromNumber = new Date(543387600000);
  9.  
  10. // create variable with specified date+time
  11. var dateBirthTime = new Date(1987,2,22,1,32);
  12.  
  13. // find a difference between two dates EG. find the number of days til next NYE:
  14. // get current year, make date using that with December (month=11), day 31
  15. var NYEdate = new Date((new Date()).getFullYear(), 11, 31);
  16. var nowdate = new Date();
  17. // convert difference in milliseconds to days
  18. var nDiffDays = Math.floor((NYEdate - nowdate)/86400000);
  19. trace(nDiffDays);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.