在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):github/time-elements开源软件地址(OpenSource Url):https://github.com/github/time-elements开源编程语言(OpenSource Language):TypeScript 49.8%开源软件介绍(OpenSource Introduction):<time> element extensionsFormats a timestamp as a localized string or as relative text that auto-updates in the user's browser. This allows the server to cache HTML fragments containing dates and lets the browser choose how to localize the displayed time according to the user's preferences. For example, the server may have cached the following generated markup: <local-time datetime="2014-04-01T16:30:00-08:00">
April 1, 2014 4:30pm
</local-time> Every visitor is served the same markup from the server's cache. When it reaches the browser, the custom <local-time datetime="2014-04-01T16:30:00-08:00">
1 Apr 2014 21:30
</local-time> Dates are displayed before months, and a 24-hour clock is used, according to the user's browser settings. If the browser's JavaScript is disabled, the default text served in the cached markup is still displayed. InstallationAvailable on npm as @github/time-elements.
UsageThis component provides three custom subtypes of the standard HTML relative-timeA relative time-ago-in-words description can be generated by using the Add a <relative-time datetime="2014-04-01T16:30:00-08:00">
April 1, 2014
</relative-time> Depending on how far in the future this is being viewed, the element's text will be replaced with one of the following formats:
So, a relative date phrase is used for up to a month and then the actual date is shown. time-untilYou can use
Add a <time-until datetime="2024-04-01T16:30:00-08:00">
April 1, 2024
</time-until> time-agoAn always relative time-ago-in-words description can be generated by using the <time-ago datetime="2012-04-01T16:30:00-08:00">
April 1, 2014
</time-ago> For example, if this markup is viewed two years in the future, the element's text will read Micro formatThe optional <time-ago datetime="2012-04-01T16:30:00-08:00" format="micro">
April 1, 2014
</time-ago> local-timeThis custom time extension is useful for formatting a date and time in the user's preferred locale format. <local-time datetime="2014-04-01T16:30:00-08:00"
month="short"
day="numeric"
year="numeric"
hour="numeric"
minute="numeric">
April 1, 2014 4:30PM PDT
</local-time> When this markup is viewed in a CDT timezone, it will show Options
Browser SupportBrowsers without native custom element support require a polyfill.
See AlsoMost of this implementation is based on Basecamp's local_time component. Thanks to @javan for open sourcing that work and allowing for others to build on top of it. @rmm5t's jquery-timeago is one of the old time-ago-in-words JS plugins. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论