File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Return day of year counting January 1 as 1
2
+ // And the last day of the year 365
3
+ // (ranging from 1-365)
4
+ // January 1 = 1
5
+ // January 2 = 2
6
+ // ...
7
+ // February 1 = 32
8
+ // February 2 = 33
9
+ // February 3 = 34
10
+ // ...
11
+ function day_of_year_today ( ) {
12
+ let now = new Date ( ) ;
13
+ let start = new Date ( now . getFullYear ( ) , 0 , 0 ) ;
14
+ let diff = ( now - start ) + ( ( start . getTimezoneOffset ( ) - now . getTimezoneOffset ( ) ) * 60 * 1000 ) ;
15
+ let one_day = 1000 * 60 * 60 * 24 ;
16
+ let day_of_year = Math . floor ( diff / one_day ) ;
17
+ return day_of_year ;
18
+ }
19
+
20
+ // Convert string "16:30:00" to "3:30 PM"
21
+ function military_to_standard ( time ) {
22
+ time = time . split ( ':' ) ; // convert to array
23
+ let hours = Number ( time [ 0 ] ) ;
24
+ let minutes = Number ( time [ 1 ] ) ;
25
+ let seconds = Number ( time [ 2 ] ) ;
26
+ let timeValue ;
27
+ if ( hours > 0 && hours <= 12 ) { timeValue = "" + hours ; } else if ( hours > 12 ) { timeValue = "" + ( hours - 12 ) ; } else if ( hours == 0 ) { timeValue = "12" ; }
28
+ timeValue += ( minutes < 10 ) ? ":0" + minutes : ":" + minutes ; // get minutes
29
+ timeValue += ( seconds < 10 ) ? ":0" + seconds : ":" + seconds ; // get seconds
30
+ timeValue += ( hours >= 12 ) ? " PM" : " AM" ; // get AM/PM
31
+ return timeValue ;
32
+ }
You can’t perform that action at this time.
0 commit comments