GithubHelp home page GithubHelp logo

nunchakus888 / dateformat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dolymood/dateformat

0.0 2.0 0.0 214 KB

Date Format--javascript js

Home Page: http://blog.aijc.net/DateFormat/

License: MIT License

JavaScript 67.41% HTML 32.59%

dateformat's Introduction

DateFormat

Date Format是一个日期格式化的库.

提供的全局的接口DateFormat(DF).支持中文、英文

日期格式化 DateFormat 使用:

格式化依据的字符串关键字 可以是一下字符组合:

y M d H h a ap A AP m s z %

例如:

'MM dd yyyy dddd hh:mm:ss'

说明:y--年、M--月、d|dd--日、ddd|dddd--星期、H--24小时制小时数、h--12小时制小时数、a|ap--am pm、A|AP--AM PM、m--分钟、s--秒、z--毫秒、%--当一些关键字连在一起的时候需要区分的字符

1、DataFormat静态方法

DF.format(d, 'dd.MM.yyyy. HH:mm:ss.zzz'); // 31.07.2013. 10:48:19.751
DF.format(d, 'yyyy年M月dd日 HH:mm:ss.zzz'); // 2013年7月31日 10:48:19.751
DF.format(d, 'yyyy年MM月dd日 dddd HH:mm:ss.zzz'); // 2013年07月31日 星期三 10:48:19.751
DF.format(d, 'yyyy年MMM%dd日 HH:mm:ss.zzz'); // 2013年7月31日 10:48:19.751
DF.parseFormatted('2013年7月29日 2:50:06.570pm', 'yyyy年M月dd日 h:mm:ss.zzz%a'); // Mon Jul 29 2013 14:50:06 GMT+0800 (**标准时间)
DF.parseFormatted('2013年7月29日 2:50:06.570am', 'yyyy年M月dd日 h:mm:ss.zzz%ap'); // Mon Jul 29 2013 02:50:06 GMT+0800 (**标准时间)
DF.prettyDate(d, 'GB'); // 刚刚
DF.prettyDate(d, 'US'); // just now
DF.prettyDate(dd, 'GB'); // 1秒以前
DF.prettyDate(dd, 'US'); // 1 second ago
DF.prettyDate(dd, 'GB'); // 6秒以前
DF.prettyDate(dd, 'US'); // 6 seconds ago
DF.prettyDate(dd, 'GB'); // 1分钟以前
DF.prettyDate(dd, 'US'); // 1 minute ago
DF.prettyDate(dd, 'GB'); // 31分钟以前
DF.prettyDate(dd, 'US'); // 31 minutes ago
DF.prettyDate(dd, 'GB'); // 今天 09:47
DF.prettyDate(dd, 'US'); // Today 09:47
DF.prettyDate(dd, 'GB'); // 今天 06:47
DF.prettyDate(dd, 'US'); // Today 06:47
DF.prettyDate(dd, 'GB'); // 昨天 09:47
DF.prettyDate(dd, 'US'); // Yesterday 09:47
DF.prettyDate(dd, 'GB'); // 7月28日 09:47
DF.prettyDate(dd, 'US'); // 28/7 09:47
DF.prettyDate(dd, 'GB'); // 6月11日 09:47
DF.prettyDate(dd, 'US'); // 11/6 09:47
DF.prettyDate(dd, 'GB'); // 3月3日 09:47
DF.prettyDate(dd, 'US'); // 3/3 09:47
DF.prettyDate(dd, 'GB'); // 2012年8月3日 09:47
DF.prettyDate(dd, 'US'); // 3/8/2012 09:47
DF.prettyDate(dd, 'GB'); // 2010年8月3日 09:47
DF.prettyDate(dd, 'US'); // 3/8/2010 09:47

此外还有:_mix type now getQR parse pad convertTo12Hour convertTo24Hour parseToInt_等方法,具体可参见源代码

2、DateFormat原型方法

df.toFormattedString('dd.MM.yyyy. HH:mm:ss.zzz'); // 31.07.2013. 10:50:27.864
df.toFormattedString('dd.MM.yyyy. HH:mm:ss.z'); // 31.07.2013. 10:50:27.864
df.toFormattedString('yyyy年M月dd日 HH:mm:ss.zzz'); // 2013年7月31日 10:50:27.864
df.toFormattedString('yyyy年MM月dd日 HH:mm:ss.zzz'); // 2013年07月31日 10:50:27.864
df.toFormattedString('yyyy年MMM%dd日 HH:mm:ss.zzz'); // 2013年7月31日 10:50:27.864
df.fromFormattedString('2013年7月29日 2:50:06.570pm', 'yyyy年M月dd日 h:mm:ss.zzz%a'); // Mon Jul 29 2013 14:50:06 GMT+0800 (**标准时间)
df.fromFormattedString('2013年7月29日 2:50:06.570am', 'yyyy年M月dd日 h:mm:ss.zzz%ap'); // Mon Jul 29 2013 02:50:06 GMT+0800 (**标准时间)
// 原型上的prettyDate方法和静态方法prettyDate基本一样.此处省略.

此外还有:_setdate getQR_等方法,具体可参见源代码

dateformat's People

Contributors

dolymood avatar

Watchers

 avatar  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.