Advertisement
BobMe

Military Clock Converter but in JavaScript

Feb 27th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // Test here: https://rextester.com/l/js_online_compiler
  2.  
  3. var seconds = 34534345;
  4. var minutes = 0;
  5. var hours = 0;
  6. var days = 0;
  7. var years = 0;
  8.  
  9. while (seconds >= 60) {
  10. seconds-=60;
  11. minutes++;
  12. }
  13.  
  14. while (minutes >= 60) {
  15. minutes-=60;
  16. hours++;
  17. }
  18.  
  19. while (hours >= 24) {
  20. hours-=24;
  21. days++;
  22. }
  23.  
  24. while (days >= 365) {
  25. days-=365;
  26. years++;
  27. }
  28.  
  29. // LINE OF STRINGS ------------------------------------
  30.  
  31. if (years < 10) {
  32. years = years.toString();
  33. years = "0"+years;
  34. }
  35. if (days < 10) {
  36. days = days.toString();
  37. days = "0"+days;
  38. }
  39. if (hours < 10) {
  40. hours = hours.toString();
  41. hours = "0"+hours;
  42. }
  43. if (minutes < 10) {
  44. minutes = minutes.toString();
  45. minutes = "0"+minutes;
  46. }
  47. if (seconds < 10) {
  48. seconds = seconds.toString();
  49. seconds = "0"+seconds;
  50. }
  51.  
  52. print("yy:dd:hh:mm:ss")
  53. print(years+":"+days+":"+hours+":"+minutes+":"+seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement