Skip to content

Commit

Permalink
Re-write getTimestamp to be in standard time and include am/pm #2
Browse files Browse the repository at this point in the history
Re-wrote the getTimestamp function to display the time in standard time by subtracting twelve when getHours is >12. Added P.M. and A.M. tags based on hour.
  • Loading branch information
Jack Perala committed Mar 31, 2020
1 parent c77fda4 commit 27d4395
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/src/app/notes/note.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ export class NoteService {
// Create a date object with the current time
const now: Date = new Date();
// Create an array with the current month, day and time
if (now.getHours() > 12) {
const date: Array<string> = [ String(now.getMonth() + 1), String(now.getDate()), String(now.getFullYear()) ];
// Create an array with the current hour, minute and second
const time: Array<string> = [ String(now.getHours() - 12), String(now.getMinutes()), String(now.getSeconds())];
// Return the formatted string
return date.join('-') + ' P.M.' + ' ' + time.join(':');
} else {
const date: Array<string> = [ String(now.getMonth() + 1), String(now.getDate()), String(now.getFullYear()) ];
// Create an array with the current hour, minute and second
const time: Array<string> = [ String(now.getHours()), String(now.getMinutes()), String(now.getSeconds())];
// Return the formatted string
return date.join('-') + ' ' + time.join(':');
return date.join('-') + ' A.M.' + ' ' + time.join(':');
}
}
}

0 comments on commit 27d4395

Please sign in to comment.