simplertime
v1.0.8
Published
Parse time string (parseTime) & convert Date to time string (timeToString)
Downloads
5
Readme
"simplertime" time-of-day library
Parses and prints time values stored as Date or number (number of milliseconds since midnight).
- 1.6KB minified
- Parses many formats: 12, 1234, 12:34, 12:34pm, 12:34 PM, 12:34:56 pm, 12:34:56.789
- Understands UTC and local time
- Full documentation is in the source code (for IntelliSense).
Example
import { parseTime, timeToString, timeToStringUTC } from 'simplertime';
var now = Date.now();
console.log("Local time (24-hour clock, no seconds): " +
timeToString(now, {use24hourTime: true, showSeconds: false}));
console.log("Local time (12-hour clock with seconds): " +
timeToString(now, {showSeconds: true}));
var fmt = {
am: " in the morning",
pm: " in the afternoon",
evening: " at night"
};
var later = now + parseTime("7:15"); // add 7 hours and 15 minutes
console.log("Seven hours and 15 minutes later is " + timeToString(later, fmt));
console.log("Which in UTC time is .............. " + timeToStringUTC(later, fmt));
console.log("Noon UTC converted to local time is " +
timeToString(parseTime("12PM"), fmt));
console.log("Noon local time converted to UTC is " +
timeToStringUTC(parseTime("12PM", new Date()), fmt));
♥ This package was made to help people learn TypeScript & React.