사이트 내 전체검색
Datejs - Date Liberary
로빈아빠
https://cmd.kr/javascript/717 URL이 복사되었습니다.

본문

Datejs - Date Liberary

Datejs 는 Date 함수를 모아 놓은 라이브러리 입니다. 거의 모든 date에 관련된 작업을 수행 할 수 있고 한국어도 따로 준비해 놓고 있습니다. 여기서 다운로드 하세요

The following is a list of precedence if including the <script> files individually. Each file requires the one above it. For example, core.js requires a CultureInfo file.

1. CultureInfo - Contains all Globalized strings and culture specific properties. Debug versions available within the /trunk/source/globalization/ folder.
2. core.js - All core Date processing logic.
3. sugarpak.js - All syntactical sugar.
4. parser.js - All parsing logic.Example Usage

Syntax Overview
Date.today()                    // Returns today's date, with time set to 00:00 (start of day).

Date.today().next().friday()    // Returns the date of the next Friday.
Date.today().last().monday()    // Returns the date of the previous Monday.

new Date().next().march()       // Returns the date of the next March.
new Date().last().week()        // Returns the date one week ago. 

Date.today().is().friday()      // Returns true|false if the day-of-week matches.
Date.today().is().fri()         // Abbreviated day names. 

Date.today().is().november()    // Month names.
Date.today().is().nov()         // Abbreviated month names.

Date.today().is().weekday()     // Is today a weekday?

Date.today().addDays(1)         // Add one day (+1).
Date.today().addMonths(-3)      // Subtract three months (-3).

Date.today().add(1).day()       // Add one (+1) day. Supports all date parts (year, month, day, hour, minute, second, millisecond, and weeks)
Date.today().add(-3).months()   // Subtract three (-3) months.

(1).day().fromNow()             // One (1) day from now. 
(3).months().ago()              // Three (3) months ago.

var n = 6;
n.months().fromNow()            // Six (6) months from now.

Date.monday()                   // Returns Monday of the current week.
Date.mon()                      // Abbreviated version of Date.monday()

Date.march()                    // Returns March 1st of this year.
Date.mar()                      // Abbreviated version of Date.march()

Date.today().first().thursday() // Returns the first Thursday of the current month.
Date.today().second().thursday()// Returns the second Thursday of the current month.

Date.march().third().thursday() // Returns the third Thursday in March of the current year.
Date.october().fourth().sunday()// Returns the fourth Sunday in October.

Date.today().fifth().sunday()   // Returns the fifth Sunday in the current month, or throws a RangeError exception if there are not 5 Sundays in the current month.
Date.october().final().sunday() // Returns the final Sunday in October.

Date.january().first().monday() // Returns the first Monday of the current year.
Date.december().final().friday()// Returns the last Friday of the current year.


Parsing
The following list is only a small subset of hundreds of string formats which can be parsed correctly without providing a date format. All parsing is fully Globalized by including the appropriate CultureInfo file. The CultureInfo file contains all the strings used for parsing and formatting.

All CultureInfo files can be found in the /trunk/source/globalization/ folder.

The following .parse() samples use the en-US.js CultureInfo file.

Date.parse('t')                 // Returns today's date.
Date.parse('today')             // Returns today's date.
Date.parse('tomorrow')          // Returns tomorrow's date.
Date.parse('yesterday')         // Returns yesterday's date.

Date.parse('next friday')       // Returns the date of the next Friday.
Date.parse('last monday')       // Returns the date of the previous Monday.

Date.parse('July 8th, 2004')    // Thu Jul 08 2004
Date.parse('15-Jan-2004')       // Thu Jan 15 2004

Date.parse('7/1/2004')          // Thu Jul 01 2004
Date.parse('7.1.2004')          // Thu Jul 01 2004
Date.parse('07.15.04')          // Thu Jul 15 2004

Date.parse('July 23rd 2004')    // Fri Jul 23 2004
Date.parse('Sat July 3, 2004')  // Sat Jul 03 2004

Date.parse('10:30 PM EST')      // Wed Oct 31 2007 20:30:00
Date.parse('10PM')              // Wed Oct 31 2007 22:00:00

Date.parse('t + 5d')            // Adds 5 days to today.
Date.parse('today - 1 month')   // Subtracts 1 month from today.

Date.parse('+')                 // Add 1 day to today = tomorrow.
Date.parse('- 3months')         // Subtract 3 months.

Date.parse('+1year')            // Add a year to today.
Date.parse('-12 months')        // Subtract 12 months (1 year) from today.

Date.parse('July 4th')          // July 4th of this year.
Date.parse('15')                // 15th day of current month/year.

Date.parse('July 8th, 2004, 10:30 PM')      // Thu Jul 08 2004 22:30:00
Date.parse('2004-07-15T06:45:00')           // Thu Jul 15 2004 06:45:00
Date.parse('Thu, 1 July 2004 22:30:00 GMT') // Thu Jul 01 2004 16:30:00

Date.parse('1997-07-16T19:20:15')           // ISO 8601 Formats
Date.parse('1997-07-16T19:20:30+01:00')     // ISO 8601 with Timezone offset
Date.parse('1985-04-12T23:20:50Z')          // RFC 3339 FormatsChaining
Date.today().add({ months: 1, days: 5 }).is().fri()        // Add 1 month and 5 days, then check if that date is a Friday.
Date.parse('10-July-2004').next().friday().add(-1).month() // Take in a date, then move to the next friday and subtract a month.


Comparison
Date.today().equals( Date.parse('today'))                  // true|false
Date.parse('last Tues').equals(Date.today())               // true|false

Date.equals(Date.today(), Date.parse('today'))             // true|false
Date.compare(Date.today(), Date.parse('today'))            // 1 = greater, -1 = lessthan, 

Date.today().compareTo(Date.parse('yesterday'))            // 1 = greater, -1 = lessthan, 0 = equal
Date.today().between(startDate, endDate)                   // true|false

댓글목록

등록된 댓글이 없습니다.

831 (5/17P)

Search

Copyright © Cmd 명령어 18.226.222.132