New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aiursoft/utctime.js

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aiursoft/utctime.js

Auto utc time

  • 1.0.5
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

UtcTime.js

MIT licensed Pipeline stat ManHours npm npm

@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"><!-- In your tag the time shall be an UTC time --></p>

Add init the library.

<script>
  new UtcTime({})
</script>

And open it now! The time will be converted to local time.

API

// Init with loop
new UtcTime({
  // We will try to select elements using the attr value. Default value is 'data-utc-time'.
  attr: 'data-utc-time',

  // Localization options. Default is ' days ago'
  daysAgo: '天前',

  // Localization options. Default is ' hours ago'
  hoursAgo: '小时前',

  // Localization options. Default is ' mintes ago'
  minutesAgo: '分钟前',

  // Localization options. Default is ' seconds ago'
  secondsAgo: '秒前',

  // Always display time and date not `some time` ago.
  disableAgo: false,

  // After the content is replaced.
  onSet: function (element, date) {},

  // Disable auto update the value by seconds.
  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.

FAQs

Package last updated on 21 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc