@zohodesk/utils
Version:
DOT Utils Collection
18 lines (17 loc) • 645 B
JavaScript
export default function getCurrentTime() {
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const ampm = hours >= 12 ? 'PM' : 'AM';
const formattedHours = hours % 12 || 12; // Convert 24-hour time to 12-hour format
const hours24 = hours.toString().padStart(2, '0');
return {
format12h: `${formattedHours}:${minutes}:${seconds} ${ampm}`,
format24h: `${hours24}:${minutes}:${seconds}`,
hours: hours,
minutes: parseInt(minutes),
seconds: parseInt(seconds),
meridiem: ampm
};
}