Converts time representation from string to number or from number to string.
Note: It was extracted from react-bootstrap-time-picker and has very limited functionality.
npm install time-number
timeFromInt(timeNumber: number, options: { validate: boolean, format: 12|24, leadingZero: boolean })
Converts number of seconds to the time string
Option | Default | Description |
---|---|---|
validate | true | By default validates provided input. You may disable it to get a better performance if you don't expect wrong input |
format | 24 | Define 12 or 24 hour format |
leadingZero | true | Controls hour leading zero |
import { timeFromInt } from 'time-number';
console.log(timeFromInt(64800)); // -> '18:00'
console.log(timeFromInt(64805)); // -> '18:00:05'
console.log(timeFromInt(64800, { format: 12 })); // -> '06:00 PM'
console.log(timeFromInt(64805, { format: 12, leadingZero: false })); // -> '6:00:05 PM'
validate
is true
by default
import { timeToInt } from 'time-number';
console.log(timeToInt('18')); // -> 64800
console.log(timeToInt('18:00')); // -> 64800
console.log(timeToInt('18:00:05')); // -> 64805
console.log(timeToInt('6:00 PM')); // -> 64800
console.log(timeToInt('6:00:05 AM')); // -> 21605
MIT (c) Yury Dymov