Code Monkey home page Code Monkey logo

datetime.js's Introduction

datetime.js

A New JavaScript Date Library.

DateTime is a thin wrapper around JavaScript's native.object and provides enhanced functionality for parsing, formatting, and manipulating dates.

How to use

DateTime has all methods of Date.

You can get DateTime object as follows:

var d1 = new DateTime();
var d2 = new DateTime(2012,11,27);
var d3 = new DateTime(2012,11,27,20,3,30);
var d4 = new DateTime(d1);
var d5 = new DateTime(new Date());
var d6 = DateTime.clone(d2);
var d7 = DateTime.today();
var d8 = DateTime.now();

You can get the string and parse string

var timeStr1 = d1.toString("Time is yyyy-MM-dd HH:mm:ss");
var timeStr2 = d1.toString("also can get like this yy-MM-dd");

var date1 = DateTime.parse(timeStr1,"Time is yyyy-MM-dd HH:mm:ss");

### DateTime support compare time

var earlier = d2.compareTo(d3);
var same = d4.compareTo(d1);
var later = d8.compareTo(d7);

DateTime support add and span methods

d1.addYears(year);
d1.addMonths(month);
d1.addDays(day);
d1.addHours(hour);
d1.addMinutes(min);
d1.addSeconds(sec);
d1.addMillseconds(milsec);

var spanYear = d1.spanYear(d2);
var sapnMonth = d1.spanMonth(d2);
var spanDay = d1.spanDay(d2);
var spanHour = d1.spanHour(d2);
var spanMin = d1.spanMinute(d2);
var spanSec = d1.spanSecond(d2);

Some another methods

var time = d3.toDate();
var valid = DateTime.validDate(d3);
var leapYear = DateTime.isLeapYear(2012);
var days1 = DateTime.getDaysInMonth(2012,1);

You can get every thing at https://github.com/brucefengnju/datetime.js

datetime.js's People

Contributors

brucefengnju avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mfine2

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.