format_date_time_moment v1.14.9
THIS MODULE HAS BEEN DEPRECIATED AND HAS BEEN MOVED TO THIS INSTEAD:
- what this means: this package will still work, but it won't be as organized and won't be updated.
- more practically, check out when_you_free - it has all these functionalities and more.
format_date_time_moment
The purpose is to make it easier to format dates (given whatever input the date may be in)
Table of Contents
Install
Directions
- Install the package
npm install format_date_time_moment
If utilizing in node, import into your javascript file like such
pay attention to the format_date_time_moment/node here
const {formatDateTime} = require("format_date_time_moment/node")
otherwise...
- In your html document, import the script (make sure to import it after your JQuery AND moment script, and before your javascript file)
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.js' integrity='sha512-Bm8FBfOFILW7qzf514l/KJaW+VKYyErRPjBRcpCJ1IfmBJcL9PRSBo6fyhE0i8BBmBbiMyQrNC97m1b1dDWM0g==' crossorigin='anonymous'></script>
<script src='https://cdn.jsdelivr.net/npm/format_date_time_moment/index.js' type='text/javascript'></script>
- Create javascript file - make sure to put all your jquery selectors after the instantiator - e.g.,
$(() => {
console.log(formatDateTime.getType("2022-03-01T19:06:31.047Z"))
})
<script src="yourScript.js"></script>
API
## FormatDateTime
Kind: global class
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
- FormatDateTime
- new FormatDateTime()
- .getType(date) ⇒ any
- .catchError(getDate) ⇒ any
- .isBefore(start, end) ⇒ boolean
- .getDuration(start, end, type) ⇒ integer
- .getReadableFormat(getDate, type) ⇒ string
- .difference(one, two, type) ⇒ integer
- .format(date, type) ⇒ any
- .digitalToSeconds(string) ⇒ integer
- .formatDateToPost(stringInput) ⇒ date
- .secondsString(seconds) ⇒ string
- .isBetween(start, end) ⇒ boolean
- .secondsToDigital(seconds) ⇒ any
- .getDate(getDate, option) ⇒ any
new FormatDateTime()
let formatDateTime = new FormatDateTime()
formatDateTime.getType(date) ⇒ any
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
date | any |
Example
getType(Date)
"2022-03-01T19:06:31.047Z"
"00:22:00"
"March 1, 2022"
"Mar 1, 2022"
"2022-03-01"
"01-03-2022"
"2022/03/01"
new Date()
23
formatDateTime.catchError(getDate) ⇒ any
catchError(date) Sees if getDate is undefined or not an object. if so, return const ERROR_OBJECT = { error: "not valid date", error_location: "format_date_time_moment", message: "date error" }
Kind: instance method of FormatDateTime
Date: 2022-03-01
Param | Type |
---|---|
getDate | any |
formatDateTime.isBefore(start, end) ⇒ boolean
Good to use if you want to see a date is before another
Kind: instance method of FormatDateTime
Date: 2022-01-20
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
start | any |
end | any |
Example
console.log(formatDateTime.isBetween("March 3, 2020", "March 10, 2021"))
formatDateTime.getDuration(start, end, type) ⇒ integer
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
start | any |
end | any |
type | any |
Example
console.log(formatDateTime.getDuration("2022-03-01T19:06:31.047Z", "2022-03-01T20:04:32.047Z", "seconds")) // 3481
console.log(formatDateTime.getDuration("2022-04-01T19:06:31.047Z", "2022-06-01T20:04:32.047Z", "days")) // 61.040289351851854
formatDateTime.getReadableFormat(getDate, type) ⇒ string
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type | Default |
---|---|---|
getDate | any | |
type | any | from |
Example
getReadableFormat("Dec 11, 2012", "from") in 2 months
getReadableFormat("Dec 11, 2012", "to") 2 months ago
formatDateTime.difference(one, two, type) ⇒ integer
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
one | any |
two | any |
type | any |
Example
console.log(formatDateTime.difference("00:22:00", "00:44:00", "seconds"))
console.log(formatDateTime.difference("March 1, 2020", "March 1, 2021", "months"))
formatDateTime.format(date, type) ⇒ any
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type | Description |
---|---|---|
date | any | |
type | any | localInput, dateInput, timeInput, |
Example
TO SECONDS formatDateTime.format("00:00:10", "") // 10
TO CASUAL formatDateTime.format("", "")
TO BEFORE
console.log(formatDateTime.format("Dec 11, 2012", "HHMMSS"))
console.log(formatDateTime.format("March 1, 2022", "dateInput")) 2022 - 03 - 01 < input type = "date" / >
// console.log(formatDateTime.format("March 1, 2022", "timeInput")) 00:00:00 <input type="time" step="1" />
// console.log(formatDateTime.format("March 1, 2022", "LL")) March 1, 2002
console.log(formatDateTime.format("March 1, 2022", "localInput")) 2022 - 03 - 01 T00: 00: 00 < input type = "datetime-local"
step = "1" / >
formatDateTime.digitalToSeconds(string) ⇒ integer
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
string | any |
Example
digitalToSeconds(00:33:22) -> seconds
formatDateTime.formatDateToPost(stringInput) ⇒ date
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
stringInput | any |
Example
formatDateToPost(stringInput)
formatDateTime.secondsString(seconds) ⇒ string
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
seconds | any |
Example
secondsString(seconds)
formatDateTime.isBetween(start, end) ⇒ boolean
Good to use if you want to see a date is before another
Kind: instance method of FormatDateTime
Returns: boolean - or object
Date: 2022-01-20
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
start | any |
end | any |
formatDateTime.secondsToDigital(seconds) ⇒ any
console.log(formatDateTime.secondsToDigital(23423)) 06: 30: 23
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
seconds | any |
formatDateTime.getDate(getDate, option) ⇒ any
getDate(date, options)
Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11
Param | Type |
---|---|
getDate | any |
option | any |
Create
let march2 = formatDateTime.getDaysAgo(2) // March 2, 2022
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago