Logo
doctype [?]
[strict] [loose] [none]

Date Formatting And Format Validation


Successful tests will be green, unsuccessful tests will be red.

Class Methods

parseString

Test #1 : new Date(2000,0,2).equals(Date.parseString('January 2, 2000','MMM d, yyyy')) Test #2 : new Date(2000,0,2).equals(Date.parseString('Jan 2, 2000','MMM d, yyyy')) Test #3 : new Date(2000,1,2).equals(Date.parseString('Feb 2, 2000','MMM d, yyyy')) Test #4 : new Date(2000,0,2).equals(Date.parseString('1/2/2000','M/d/yyyy')) Test #5 : new Date(2000,0,2).equals(Date.parseString('2000-01-02','yyyy-MM-dd')) Test #6 : new Date(2000,0,2).equals(Date.parseString('00-01-02','yy-MM-dd')) Test #7 : new Date(1980,0,2).equals(Date.parseString('80-01-02','yy-MM-dd')) Test #8 : new Date(2000,0,2,16,30).equals(Date.parseString('Jan 2 2000 4:30pm','NNN d y h:ma')) Test #9 : new Date(2000,0,2,4,30).equals(Date.parseString('Jan 2 2000 04:30am','NNN d y hh:ma')) Test #10 : new Date(2000,0,2,4,30).equals(Date.parseString('Jan 2 2000 03:30am','NNN d y KK:ma')) Test #11 : new Date(2000,0,2,16,30,30).equals(Date.parseString('Jan 2 2000 05:30:30pm','NNN d y kk:m:ssa')) Test #12 : Date.parseString('January 1, 2000','MMM dd, yyyy')==null Test #13 : Date.parseString('2/31/2000','M/d/y')==null Test #14 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('January 2')) Test #15 : new Date(2000,0,2).equals(Date.parseString('2000-01-02')) Test #16 : new Date(2000,0,2).equals(Date.parseString('January 2, 2000')) Test #17 : new Date(2000,0,2).equals(Date.parseString('January 2,2000')) Test #18 : new Date(2000,0,2).equals(Date.parseString('2000-January-2')) Test #19 : new Date(2000,0,2).equals(Date.parseString('02-January-00')) Test #20 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('January-2')) Test #21 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('2-January')) Test #22 : Date.parseString('2?1?2000') == null Test #23 : Date.parseString('99:99','hh:mm') == null Test #24 : Date.parseString('99:99','HH:mm') == null Test #25 : Date.parseString('99:99','KK:mm') == null Test #26 : Date.parseString('99:99','kk:mm') == null Test #27 : Date.parseString('01:99','HH:mm') == null Test #28 : Date.parseString('01:01:99','HH:mm:ss') == null Test #29 : Date.parseString('01:01XX','h:ma') == null Test #30 : Date.parseString('01:01 XXX','h:m') == null Test #31 : Date.parseString('2/31/2001') == null Test #32 : Date.parseString('4/31/2001') == null

Date.preferAmericanFormat = false

Test #33 : new Date(2000,0,2).equals(Date.parseString('2/1/2000')) Test #34 : new Date(2000,0,2).equals(Date.parseString('2-1-2000')) Test #35 : new Date(2000,0,2).equals(Date.parseString('2.1.2000')) Test #36 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('02/01')) Test #37 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('02-01'))

Date.preferAmericanFormat = true

Test #38 : new Date(2000,0,2).equals(Date.parseString('1/2/2000')) Test #39 : new Date(2000,0,2).equals(Date.parseString('1-2-2000')) Test #40 : new Date(2000,0,2).equals(Date.parseString('1.2.2000')) Test #41 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('01/02')) Test #42 : new Date(new Date().getFullYear(),0,2).equals(Date.parseString('01-02'))

isValid

Test #43 : Date.isValid('January 2, 2000','MMM d, yyyy') Test #44 : Date.isValid('1/2/2000','M/d/yyyy') Test #45 : Date.isValid('2000-01-02','yyyy-MM-dd') Test #46 : Date.isValid('Jan 2 2000 4:30pm','NNN d y h:ma') Test #47 : !Date.isValid('January 1, 2000','MMM dd, yyyy') Test #48 : !Date.isValid('2/31/2000','M/d/y') Test #49 : Date.isValid('January 2') Test #50 : Date.isValid('2000-01-02') Test #51 : Date.isValid('January 2, 2000') Test #52 : Date.isValid('January 2,2000') Test #53 : Date.isValid('2000-January-2') Test #54 : Date.isValid('02-January-00') Test #55 : Date.isValid('January-2') Test #56 : Date.isValid('2-January')

Instance Methods

isBefore

Test #57 : new Date(2001,1,1).isBefore(new Date(2002,1,1)) Test #58 : !(new Date().isBefore(new Date(2000,1,1))) Test #59 : new Date(2001,1,1,1,1,1,0).isBefore(new Date(2001,1,1,1,1,1,1)) Test #60 : !(new Date(2001,1,1,1,1,1,1).isBefore(new Date(2001,1,1,1,1,1,1))) Test #61 : !(new Date().isBefore(null))

isAfter

Test #62 : new Date(2002,1,1).isAfter(new Date(2001,1,1)) Test #63 : new Date().isAfter(new Date(2000,1,1)) Test #64 : new Date(2001,1,1,1,1,1,1).isAfter(new Date(2001,1,1,1,1,1,0)) Test #65 : !(new Date(2001,1,1,1,1,1,1).isAfter(new Date(2001,1,1,1,1,1,1))) Test #66 : !(new Date().isAfter(null))

clearTime

Test #67 : new Date(2001,1,1,1,1,1,1).clearTime().getTime() == new Date(2001,1,1).getTime()

equals

Test #68 : new Date(2000,1,1).equals(new Date(2000,1,1)) Test #69 : !(new Date().equals(new Date(2000,1,1))) Test #70 : !(new Date(2001,1,1,1,1,1,1).equals(new Date(2001,1,1,1,1,1,0))) Test #71 : !(new Date().equals(null))

equalsIgnoreTime

Test #72 : new Date(2000,1,1).equalsIgnoreTime(new Date(2000,1,1)) Test #73 : !(new Date().equalsIgnoreTime(new Date(2000,1,1))) Test #74 : new Date(2001,1,1,2,3,4,5).equalsIgnoreTime(new Date(2001,1,1,6,7,8,9)) Test #75 : !(new Date().equalsIgnoreTime(null))

getDayName

Test #76 : new Date(2000,0,1).getDayName() == 'Saturday' Test #77 : new Date(2000,0,2).getDayName() == 'Sunday' Test #78 : new Date(2000,0,3).getDayName() == 'Monday' Test #79 : new Date(2000,0,4).getDayName() == 'Tuesday' Test #80 : new Date(2000,0,5).getDayName() == 'Wednesday' Test #81 : new Date(2000,0,6).getDayName() == 'Thursday' Test #82 : new Date(2000,0,7).getDayName() == 'Friday'

getDayAbbreviation

Test #83 : new Date(2000,0,1).getDayAbbreviation() == 'Sat' Test #84 : new Date(2000,0,2).getDayAbbreviation() == 'Sun' Test #85 : new Date(2000,0,3).getDayAbbreviation() == 'Mon' Test #86 : new Date(2000,0,4).getDayAbbreviation() == 'Tue' Test #87 : new Date(2000,0,5).getDayAbbreviation() == 'Wed' Test #88 : new Date(2000,0,6).getDayAbbreviation() == 'Thu' Test #89 : new Date(2000,0,7).getDayAbbreviation() == 'Fri'

getMonthName

Test #90 : new Date(2000,0).getMonthName() == 'January' Test #91 : new Date(2000,1).getMonthName() == 'February' Test #92 : new Date(2000,2).getMonthName() == 'March' Test #93 : new Date(2000,3).getMonthName() == 'April' Test #94 : new Date(2000,4).getMonthName() == 'May' Test #95 : new Date(2000,5).getMonthName() == 'June' Test #96 : new Date(2000,6).getMonthName() == 'July' Test #97 : new Date(2000,7).getMonthName() == 'August' Test #98 : new Date(2000,8).getMonthName() == 'September' Test #99 : new Date(2000,9).getMonthName() == 'October' Test #100 : new Date(2000,10).getMonthName() == 'November' Test #101 : new Date(2000,11).getMonthName() == 'December'

getMonthAbbreviation

Test #102 : new Date(2000,0).getMonthAbbreviation() == 'Jan' Test #103 : new Date(2000,1).getMonthAbbreviation() == 'Feb' Test #104 : new Date(2000,2).getMonthAbbreviation() == 'Mar' Test #105 : new Date(2000,3).getMonthAbbreviation() == 'Apr' Test #106 : new Date(2000,4).getMonthAbbreviation() == 'May' Test #107 : new Date(2000,5).getMonthAbbreviation() == 'Jun' Test #108 : new Date(2000,6).getMonthAbbreviation() == 'Jul' Test #109 : new Date(2000,7).getMonthAbbreviation() == 'Aug' Test #110 : new Date(2000,8).getMonthAbbreviation() == 'Sep' Test #111 : new Date(2000,9).getMonthAbbreviation() == 'Oct' Test #112 : new Date(2000,10).getMonthAbbreviation() == 'Nov' Test #113 : new Date(2000,11).getMonthAbbreviation() == 'Dec'

format

Test #114 : new Date(2000,0,1,16,5,5,5).format('yyyy') == '2000' Test #115 : new Date(2000,0,1,16,5,5,5).format('yy') == '00' Test #116 : new Date(2000,0,1,16,5,5,5).format('MMM') == 'January' Test #117 : new Date(2000,0,1,16,5,5,5).format('NNN') == 'Jan' Test #118 : new Date(2000,0,1,16,5,5,5).format('dd') == '01' Test #119 : new Date(2000,0,1,16,5,5,5).format('d') == '1' Test #120 : new Date(2000,0,1,16,5,5,5).format('EE') == 'Saturday' Test #121 : new Date(2000,0,1,16,5,5,5).format('hh') == '04' Test #122 : new Date(2000,0,1,16,5,5,5).format('h') == '4' Test #123 : new Date(2000,0,1,16,5,5,5).format('HH') == '16' Test #124 : new Date(2000,0,1,16,5,5,5).format('KK') == '03' Test #125 : new Date(2000,0,1,16,5,5,5).format('K') == '3' Test #126 : new Date(2000,0,1,16,5,5,5).format('kk') == '17' Test #127 : new Date(2000,0,1,16,5,5,5).format('k') == '17' Test #128 : new Date(2000,0,1,16,5,5,5).format('mm') == '05' Test #129 : new Date(2000,0,1,16,5,5,5).format('m') == '5' Test #130 : new Date(2000,0,1,16,5,5,5).format('ss') == '05' Test #131 : new Date(2000,0,1,16,5,5,5).format('s') == '5' Test #132 : new Date(2000,0,1,16,5,5,5).format('a') == 'PM' Test #133 : new Date(2000,0,1,16,5,5,5).format('MM/dd/yyyy') == '01/01/2000' Test #134 : new Date(2000,0,1,16,5,5,5).format('MMM dd, yyyy h:mm:ssa') == 'January 01, 2000 4:05:05PM' Test #135 : new Date(2000,0,1,16,5,5,5).format('yyyy,MMM,NNN,dd,EE,hh,HH,KK,kk,mm,ss,a') == '2000,January,Jan,01,Saturday,04,16,03,17,05,05,PM' Test #136 : new Date(2000,0,0,0).format('h') == '12' Test #137 : new Date(2000,0,0,1).format('h') == '1'

add

years

Test #138 : new Date(2000,0,1).add('y',2).equals(new Date(2002,0,1)) Test #139 : new Date(2000,1,29).add('y',1).equals(new Date(2001,2,1))

months

Test #140 : new Date(2000,0,30).add('M',1).equals(new Date(2000,2,1)) Test #141 : new Date(2000,0,1).add('M',12).equals(new Date(2001,0,1))

days

Test #142 : new Date(2000,0,1).add('d',3).equals(new Date(2000,0,4)) Test #143 : new Date(2001,0,1).add('d',365).equals(new Date(2002,0,1)) Test #144 : new Date(2000,0,30).add('d',3).equals(new Date(2000,1,2)) Test #145 : new Date(2000,2,1).add('d',-3).equals(new Date(2000,1,27)) Test #146 : new Date(2001,2,1).add('d',-3).equals(new Date(2001,1,26))

weekdays

Test #147 : new Date(2000,0,1).add('w',13).equals(new Date(2000,0,19)) Test #148 : new Date(2000,0,1).add('w',-2).equals(new Date(1999,11,30))

hours

Test #149 : new Date(2000,0,1).add('h',5).equals(new Date(2000,0,1,5)) Test #150 : new Date(2000,0,1).add('h',26).equals(new Date(2000,0,2,2))

minutes

Test #151 : new Date(2000,0,1).add('m',5).equals(new Date(2000,0,1,0,5)) Test #152 : new Date(2000,0,1).add('m',-150).equals(new Date(1999,11,31,21,30))

seconds

Test #153 : new Date(2000,0,1).add('s',10).equals(new Date(2000,0,1,0,0,10)) Test #154 : new Date(2000,0,1).add('s',86400).equals(new Date(2000,0,2))

Error

Test #155 : new Date(2000,0,1).add(null,null).equals(new Date(2000,0,1))