Current Date and Time


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



Copy this code and paste it in your HTML
  1. function getCurrentTime(){
  2. var today = new Date();
  3. var minutes = today.getMinutes();
  4. var hours = today.getHours();
  5. var dat = today.getDate();
  6. var month = today.getMonth()+1;
  7. var year = today.getFullYear();
  8. var dayN = today.getDay();
  9. var day:String;
  10. var c_time:Number;
  11. var AM_PM:String;
  12. var is_zero_min:String;
  13. var is_zero_dat:String;
  14. var is_zero_mon:String;
  15. var output:String;
  16.  
  17. switch (dayN) {
  18. case 0 :
  19. day = "Sun";
  20. break;
  21. case 1 :
  22. day = "Mon";
  23. break;
  24. case 2 :
  25. day = "Tue";
  26. break;
  27. case 3 :
  28. day = "Wed";
  29. break;
  30. case 4 :
  31. day = "Thu";
  32. break;
  33. case 5 :
  34. day = "Fri";
  35. break;
  36. case 6 :
  37. day = "Sat";
  38. break;
  39. }
  40. if (hours>12) {
  41. c_time = (hours-12);
  42. AM_PM = "PM";
  43. }
  44. if (hours==12){
  45. c_time = 12;
  46. AM_PM = "PM";
  47. }
  48. if (hours<12){
  49. c_time = hours;
  50. AM_PM = "AM";
  51. }
  52. if (hours==0){
  53. c_time = 12;
  54. AM_PM = "AM";
  55. }
  56. if (minutes<10) {
  57. is_zero_min = "0";
  58. } else {
  59. is_zero_min = "";
  60. }
  61. if (dat<10) {
  62. is_zero_dat = "0";
  63. } else {
  64. is_zero_dat = "";
  65. }
  66. if (month<10) {
  67. is_zero_mon = "0";
  68. } else {
  69. is_zero_mon = "";
  70. }
  71. output = c_time+":"+is_zero_min+minutes+" "+AM_PM+" "+day+" "+is_zero_dat+dat+"."+is_zero_mon+month+"."+year;
  72. trace(output);
  73. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.