tarids

Tardis JS V1.6.3

Tardis JS an open source JavaScript Date library for parsing, formatting and processing. A simple, light weight and easy to implement module that you can use in your JS appication or website.

Install

Via NPM: npm i lbx-tardis

or

Include tardis.js in your build directory or link to it directly

<script type="text/javascript" src="tardis.js"></script>

Download tardis.js or tardis.min.js

Clone it on GitHub

Usage

const getDate = tardis.dateparts() // { year: 119, month: 6, day: 29, hour: 13, min: '04', sec: '12', fullYear: 2019, shortYear: '19', wordYear: 'two thousand and nineteen',  fullMonth: 'June',  shortMonth: 'Jun',....}

const getISO = tardis.ISO() // 2019-06-29

const getTimeStamp = tardis.patterned(1133481000, 'M/DD/YYYY - H:I:s TT tt'); // { pattern: '12/02/2005 - 18:50:{{26}} PM pm', time: 1133481000 }

const getTime = tardis.patterned('2019-06-29T17:26:43', 'M/DD/YYYY - HH:II:SS tt'); //{ pattern: '6/30/2019 - 18:26:43 pm', time: '2019-06-29T17:26:43' }

The Date Object

{
    
year: 125 month: 4 day: 1 hour: 2 min: "48" sec: "59" fullYear: 2025 shortYear: "25" wordYear: "two thousand and twenty five" fullMonth: "April" shortMonth: "Apr" fullDay: "Tuesday" shortDay: "Tue" wordHour: "two" wordMin: "forty eight" wordSec: "fifty nine" yearInt: 125 monthInt: 3 dayInt: 2 hourInt: 2 minInt: 48 secInt: 59 YYear: "25" MMonth: "04" DDay: "02" HHour: "02" MMin: "48" SSec: "59" TT: "PM" tt: "pm" utc: Tue Apr 01 2025 02:48:59 GMT+0000 (Coordinated Universal Time) timestamp: "1743475739"
}

Filters

By using a simple mask you can create a unique time format to meet all of your needs. Simply by invoking the patterned method, passing in a time stamp and defining a filter pattern. If you do not supply a time stamp the method will assume you want the current time and return date.Now(). The returned object ({pattern: pattern, time: theTime}) with have your patterned string and the time as a unix timestamp should you need to reuse it.

Mask
Key
Result
Legend
YYYY
thisDate.fullYear
2025
full 4 digit year
YYY
thisDate.wordYear
two thousand and twenty five
full english 4 digit year
YY
thisDate.shortYear
25
truncated string of YYYY
y
thisDate.year
125
integer value, no leading 0, years from 1970
MMMM
thisDate.fullMonth
April
name value of month from months array
MMM
thisDate.shortMonth
Apr
months[date.getMonth()].substr(0, 3)
MM
thisDate.MMonth
04
string value of month with leading 0
M
thisDate.month
4
integer value, no leading 0
m
thisDate.monthInt
3
integer value, no leading 0
DDDD
thisDate.fullDay
Tuesday
name value of day or week from Days Array
DDD
thisDat.shortDay
Tue
truncated string of DDDD
DD
thisDate.DDay
02
string value of D with leading 0
D
thisDate.day
1
integer value, no leading 0
d
thisDate.dayInt
2
Day of week counter (Sun = 0, Sat = 6)
HHHH
thisDate.wordHour
seven
string value of english text for a number
HH
thisDate.HHour
07
string value of H with leading 0
H
thisDate.hour
7
integer value, no leading 0
h
thisDate.hourInt
7
integer value, no leading 0
IIII
thisDate.wordSec
forty eight
string value of english text for a number
II
thisDate.MMin
48
string value of I with leading 0
I
thisDate.min
48
integer value, no leading 0
i
thisDate.minInt
48
integer value, no leading 0
SSSS
thisDate.wordMin
fifty nine
string value of english text for a number
SS
thisDate.sec
59
string value of S with leading 0
S
thisDate.sec
59
integer value, no leading 0
s
thisDate.secInt
59
integer value, no leading 0
TT
thisDate.hour
PM
meridiem display - upper case
tt
thisDate.hour
pm
meridiem display - lower case

Presets

Tardis JS has several prebuilt filter patterns for the most commonly used time formats. Simply, call the method of the preset format you want and set a timestamp. If you do not supply a timestamp, date.Now() will be returned.

tardis.ISO({date})                // 2025-04-1
tardis.ShortDate({date})          // 04/1/2025
tardis.LongDate({date})           // Apr 1 2025
tardis.DayMonthDate({date})       // Tuesday, April 1, 2025
tardis.MonthDateTime({date})      // April 1, 2025 7:48
tardis.MonthDateTime12({date})    // April 1, 2025 7:48 PM
tardis.MonthDate({date})          // April 1, 2025
tardis.TimeOfDay({date})          // 7:48:59
tardis.TimeOfDay12({date})        // 7:48:59 PM
tardis.Year({date})               // 2025
tardis.Month({date})              // April
tardis.Day({date})                // Tuesday