GithubHelp home page GithubHelp logo

johnnychn / date.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaywcjlove/date.js

0.0 2.0 0.0 10 KB

JavaScript function for converting timestamps or Date objects to formatted strings, manipulate dates.

HTML 5.36% JavaScript 94.64%

date.js's Introduction

date 时间操作

format

格式化时间

new Date('2015-10-12 23:01:11').format("yyyy年MM月dd日 hh:mm:ss");
//⇒ "2015年10月12日 23:01:11"

var testDate = new Date(); 
var testStr = testDate.format("yyyy年MM月dd日hh小时mm分ss秒"); 
//=> testStr =  2015年01月20日 19小时21分03秒

ago

多少小时前、多少分钟前、多少秒前

new Date(1421313395359).ago(1411430400000)
//=> "3个月前"

new Date(1421313395359).ago('1987-04-03')
//=> "28年前"

new Date('2010-02-02').ago('1987-04-03')
//=> "23年前"

toHHMMSS

时间转换,倒计时 '毫秒'.toHHMMSS(输出格式) 这个是基于 String 原型扩展出来的

var dt = (new Date().getTime()).toString()
dt.toHHMMSS('hh时mm分ss秒') //=> 34时11分52秒

TZC

解决因时区变更,导致显示服务器时间不准确

//服务端传入前端一般为秒,前端时间戳为毫秒所以要乘以1000
//8 为服务器时间时区
new Date(1434701732*1000).TZC(8)

date.js's People

Contributors

jaywcjlove avatar

Watchers

James Cloos avatar Johnny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.