-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.html
More file actions
30 lines (30 loc) · 905 Bytes
/
time.html
File metadata and controls
30 lines (30 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script>
(function(){
const now = new Date()
let hour = now.getHours()
let minute = now.getMinutes()
let second = now.getSeconds()
let millisecond = now.getMilliseconds
if( minute < 10 ){
minute = '0' + minute
}
if( second < 10 ){
second = '0' + second
}
let time = 'It is now: ' + hour + ':' + minute + ':' + second + ' and ' + millisecond + ' milliseconds'
console.log(time)
let greeting = 'Good Morning!'
if( hour > 11 ){
greeting = 'Good Afternoon!'
}
if ( hour < 17 ){
greeting = 'Good Evening!'
}
console.log( greeting )
let suffix = ( hour > 11 )?'P.M.':'A.M.'
if( hour > 12 ){
hour -= 12
}
console.log('Time is: ' + hour + ':' + minute + suffix )
})()
</script>