format12h

v0.0.3arrow_drop_down
v0.0.3
v0.0.2
v0.0.1
STATUS
Passing
DOWNLOADS
0
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 years ago
SIZE
726 B
# Formats a date object as a 12 hours time (am/pm).
1 contributor
Install format12h as a package?
Copied
npm i @bit/tomlandau.simple-js.format-date.format12h
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right

Formats a date object as a 12 hours time (am/pm).

format12h (
date:Date,
withSeconds:bool
) : string

formats a date object as a 12 hours time (am/pm), with or without seconds (without by default).

Example
format12h(new Date(2017,06,04,10,45,10)) => 10:45 am
format12h(new Date(2017,06,04,23,45,10)) => 11:45 pm
format12h(new Date(2017,06,04,23,45,10), true) => 11:45:10 pm
Arguments
date: Date
withSeconds: bool
Returns
string

Test Summary

format-12h should return formatted time with am for 1-11 hours

Pass

format-12h should return formatted time with 12 am for 0 hours

Pass

format-12h should return formatted time with pm for 12-23 hours

Pass

format-12h should return single digits with leading zeros

Pass

format-12h should return formatted time without seconds when not specified otherwise

Pass

format-12h should return formatted time with seconds when specified

Pass
Help and resources