Menu

gitpiper

getMeridiemSuffixOfInteger javascript Code Snippet in 2024

datebeginner

Last Updated: 20 March 2024

Converts an integer to a suffixed string, adding am or pm based on its value.

  • Use the modulo operator (%) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 ? 12 + 'pm' : num < 12 ? (num % 12) + 'am' : (num % 12) + 'pm';
getMeridiemSuffixOfInteger(0); // '12am' getMeridiemSuffixOfInteger(11); // '11am' getMeridiemSuffixOfInteger(13); // '1pm' getMeridiemSuffixOfInteger(25); // '1pm'

javascript snippet similar to getMeridiemSuffixOfInteger For You in March 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️