From 27d4395c2d5f2ec49671da97b542afde28694e4d Mon Sep 17 00:00:00 2001 From: Jack Perala Date: Tue, 31 Mar 2020 14:25:02 -0500 Subject: [PATCH] Re-write getTimestamp to be in standard time and include am/pm #2 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. --- client/src/app/notes/note.service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/app/notes/note.service.ts b/client/src/app/notes/note.service.ts index 5c97eda..6e456f2 100644 --- a/client/src/app/notes/note.service.ts +++ b/client/src/app/notes/note.service.ts @@ -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(now.getMonth() + 1), String(now.getDate()), String(now.getFullYear()) ]; + // Create an array with the current hour, minute and second + const time: Array = [ 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(now.getMonth() + 1), String(now.getDate()), String(now.getFullYear()) ]; // Create an array with the current hour, minute and second const time: Array = [ 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(':'); } } +}