1.0.4 • Published 6 years ago

hello-date v1.0.4

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

hello-date v1.0.4

时间日期转化工具,可将日期或时间戳转化为timeago等

npm install hello-date --save

直接页面引入

<script src="./dist/helloDate.js"></script>

模块引入

import helloDate from 'hello-date'

or

var helloDate = require('hello-date')

API

helloDate.timeago

// 参数可以是时间戳或者日期格式的字符串
var ago = helloDate.timeago('2018-6-10')  // 2个月前
var ago = helloDate.timeago(1528560000)   // 2个月前

helloDate.yesterday

// 参数可以是时间戳或者日期格式的字符串
// 超过48小时显示日期,48小时以内显示时间
var yesterday = helloDate.yesterday('2018-6-10')  // 昨天15:30
var yesterday = helloDate.yesterday(1528560000)   // 昨天15:30

helloDate.toTimestamp

// 参数为日期格式的时间
var timestamp = helloDate.toTimestamp('2018-6-10 21:32:20') // 1528637540

helloDate.toDate

// 参数为时间戳
var date = helloDate.toDate(1528637540)  // 2018-6-10 21:32:20