UtcTime.js

@aiursoft/utctime.js
is a JavaScript library which converts UTC time to local time easily.
Installation
Run the following command to install the most recent version of @aiursoft/utctime.js
from npm:
npm install @aiursoft/utctime.js
Importing
Reference JavaScript
You can import the library using the following code:
<script type="module">
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
new UtcTime({})
</script>
How to build locally
npm install
npm run build
How to use
Create an element.
<p></p>
And change it like this.
<p data-utc-time="9/12/2018 10:12:24 AM"></p>
Add init the library.
<script>
new UtcTime({})
</script>
And open it now! The time will be converted to local time.
API
new UtcTime({
attr: 'data-utc-time',
daysAgo: '天前',
hoursAgo: '小时前',
minutesAgo: '分钟前',
secondsAgo: '秒前',
disableAgo: false,
onSet: function (element, date) {},
disableAutoUpdate: false,
})
For example, to init bootstrap v4 tooltip:
new UtcTime({
onSet: function (element, date) {
element.setAttribute('data-toggle', 'tooltip')
element.setAttribute('data-trigger', 'hover')
element.setAttribute('data-title', date.toLocaleString())
$(element).tooltip()
},
})
To init bootstrap v5 tooltip:
new UtcTime({
onSet: function (element, date) {
new bootstrap.Tooltip(element, {
trigger: 'hover',
placement: 'top',
title: date.toLocaleString(),
})
},
})
How to contribute
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.