feat(FE): DateFormatter.ts
This commit is contained in:
parent
bb1c3c63d4
commit
f7a5ce1c2d
1 changed files with 20 additions and 2 deletions
|
@ -9,5 +9,23 @@ export function extractTime(dateTimeString: string, extractTime: boolean = false
|
|||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
return `${hours}:${minutes}`;
|
||||
}
|
||||
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
|
||||
};
|
||||
return date.getFullYear() + '-' + String(date.getMonth() + 1).padStart(2, '0') + '-' + String(date.getDate()).padStart(2, '0');
|
||||
};
|
||||
|
||||
export function getTimeDiff(startTime: Date, endTime: Date) {
|
||||
const diffInMilliseconds = Math.abs(startTime.getTime() - endTime.getTime());
|
||||
|
||||
const hours = Math.floor((diffInMilliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((diffInMilliseconds % (1000 * 60 * 60)) / (1000 * 60));
|
||||
|
||||
const formattedHours = String(hours).padStart(2, '0');
|
||||
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||
|
||||
return `${formattedHours}:${formattedMinutes}`;
|
||||
}
|
||||
|
||||
export function getHoursMinutesFromString(timeString: string): Date {
|
||||
const [ h, m ] = timeString.split(":");
|
||||
const ms = new Date().setHours(h,m);
|
||||
return new Date(ms)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue