3

Is there a javascript equivalent implementation of java.util.Calendar API? It will be quite handy to do date manipulation with it around.

Prashant Bhate
  • 10,907
  • 7
  • 47
  • 82
  • I had to build a complex scheduling system with the Java Calendar API a couple years ago. I will admit it is powerful and sophisticated but mainly, it is a big pain in the ass. It is way to complicated for your average date/time calculations. I just can't believe others are looking for a similar API for different languages. – Jesse Webb May 13 '11 at 20:27

2 Answers2

3

Though not exact http://momentjs.com/ is much better in many ways ! I would go for this if given a choice.

Formatting dates

moment().format('MMMM Do YYYY, h:mm:ss a');
moment().format('dddd');
moment().format("MMM Do YY");
moment().format('YYYY [escaped] YYYY');
moment().format();

September 23rd 2012, 1:29:09 am
Sunday
Sep 23rd 12
2012 escaped 2012
2012-09-23T01:29:09+01:00

Timeago

moment("20111031", "YYYYMMDD").fromNow();
moment("20120620", "YYYYMMDD").fromNow();
moment().startOf('day').fromNow();
moment().endOf('day').fromNow();
moment().startOf('hour').fromNow();

11 months ago
3 months ago
an hour ago
in a day
28 minutes ago

Calendar Time

moment().subtract('days', 10).calendar();
moment().subtract('days', 6).calendar();
moment().subtract('days', 3).calendar();
moment().subtract('days', 1).calendar();
moment().calendar();
moment().add('days', 1).calendar();
moment().add('days', 3).calendar();
moment().add('days', 10).calendar();

09/12/2012
last Sunday at 12:06 PM
last Wednesday at 12:06 PM
Yesterday at 12:06 PM
Today at 12:06 PM
Tomorrow at 12:06 PM
Tuesday at 12:06 PM

Internationalization

moment().format('L');
moment().format('LL');
moment().format('LLL');
moment().format('LLLL');

09/22/2012
September 22 2012
September 22 2012 12:07 PM
Saturday, September 22 2012 12:07 PM
Prashant Bhate
  • 10,907
  • 7
  • 47
  • 82
1

YUI 2: Calendar, I think is a similar to what you are looking for..

Also a this would get you many answers.

Community
  • 1
  • 1
niksvp
  • 5,545
  • 2
  • 24
  • 41