Js code line transfer time stamp format to achieve

javascript timestamp conversion, support for custom formats, you can display year, month, week, day, hour, minute, seconds, date and time in various forms.

It recommended a common JavaScript libraries

jutils

jutils - JavaScript libraries commonly used functions

In their daily work life, often use some date formatting, url related operations, determine the type of browser, verify the format commonly used functions, etc., although most simply Google / Baidu what can be found, but most are there some of the problems, and then finishing the online tools used in their usual, to facilitate future use, improve development efficiency.

use

Direct download jutils.min.js use, support UMD Universal module specification.

<script src="jutils.min.js"></script>
<script>
  var browser = jutils.getBrowserInfo()
</script>

Examples

Year, month, day, hour, minute, second

var date = jutils.formatDate(new Date(1533686888*1000),"YYYY-MM-DD HH:ii:ss");
console.log(date);
// 2019-07-09 19:44:01

Year, month, day, week

var date = jutils.formatDate(new Date(1562672641*1000),"YYYY-MM-DD 周W");
console.log(date);
//2019-07-09 周二

Month, day, week

var date = jutils.formatDate(new Date(1562672641*1000),"MM-DD 周W");
console.log(date);
//07-09 周二

Minutes and seconds

var date = jutils.formatDate(new Date(1562672641*1000),"HH:ii:ss");
console.log(date);
//19:44:01

Source

The following is an excerpt from jutilstime class source code:

js time stamp into date format

Guess you like

Origin www.cnblogs.com/sirdong/p/11454854.html
Recommended