Powered by GeSHi

Source code for tomorrow.js

(view source code of tomorrow.js as plain text)

  1. // Tomorrow.js,  Version 1.00 for Windows Script Host 2.00
  2. // Display today's, yesterday's and tomorrow's date in two formats
  3. //
  4. // Written by Rob van der Woude
  5. // http://www.robvanderwoude.com
  6.  
  7. // Specify header
  8. strHead1 = "Format:     YYYYMMDD  (DD/MM/YYYY)";
  9. strHead2 = "==================================";
  10.  
  11. // Create Date object
  12. objToday = new Date();
  13.  
  14. // Get today's year, month and day
  15. year  = objToday.getFullYear();
  16. month = objToday.getMonth() + 1;
  17. if ( month < 10 )
  18. 	{
  19. 	month = "0" + month;
  20. 	};
  21. day   = objToday.getDate();
  22. if ( day < 10 )
  23. 	{
  24. 	day = "0" + day;
  25. 	};
  26.  
  27. // Format output for today
  28. strToday = "Today:      " + year + month + day + "  (" + day;
  29. strToday = strToday + "/" + month + "/" + year + ")";
  30.  
  31. // Get current date in milliseconds since January 1, 1970
  32. today = objToday.valueOf();
  33.  
  34. // Subtract 1 day
  35. oneDay = 1000 * 24 * 60 * 60;
  36. yesterday = today - oneDay;
  37. objToday.setTime(yesterday);
  38.  
  39. // Get yesterday's year, month and day
  40. year  = objToday.getFullYear();
  41. month = objToday.getMonth() + 1;
  42. if ( month < 10 )
  43. 	{
  44. 	month = "0" + month;
  45. 	};
  46. day   = objToday.getDate();
  47. if ( day < 10 )
  48. 	{
  49. 	day = "0" + day;
  50. 	};
  51.  
  52. // Format output for yesterday
  53. strYest = "Yesterday:  " + year + month + day + "  (" + day;
  54. strYest = strYest + "/" + month + "/" + year + ")";
  55.  
  56. // Add 1 day
  57. oneDay = 1000 * 24 * 60 * 60;
  58. tomorrow = today + oneDay;
  59. objToday.setTime(tomorrow);
  60.  
  61. // Get tomorrow's year, month and day
  62. year  = objToday.getFullYear();
  63. month = objToday.getMonth() + 1;
  64. if ( month < 10 )
  65. 	{
  66. 	month = "0" + month;
  67. 	};
  68. day   = objToday.getDate();
  69. if ( day < 10 )
  70. 	{
  71. 	day = "0" + day;
  72. 	};
  73.  
  74. // Format output for tomorrow
  75. strTomor = "Tomorrow:   " + year + month + day + "  (" + day;
  76. strTomor = strTomor + "/" + month + "/" + year + ")";
  77.  
  78. // Display the result
  79. WScript.Echo( strHead1 );
  80. WScript.Echo( strHead2 );
  81. WScript.Echo( strYest );
  82. WScript.Echo( strToday );
  83. WScript.Echo( strTomor );
  84.