File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript Date Formats and new Date() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "JavaScript Date Formats and new Date()" Watch "JavaScript Date Formats and new Date()" New topic
Author

JavaScript Date Formats and new Date()

Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Originally all our dates were in the format MM/dd/yyyy across the board. The client wants them MM-dd-yy. I ran into some JavaScript bugs after the change. Specifically...



I'm pulling the date string from a text input. I'm a) not sure why JavaScript will parse one and not the other and b) what I can do to get JavaScript to parse the latter.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56540
    
  14

I hate dealing with dates with a passion. Can you use the date parsing utility function provided by the jQuery UI datepicker? If not, you might need to regex the string and reform it to something that Date() likes. Icky icky icky.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Tom Varga
Greenhorn

Joined: Aug 09, 2010
Posts: 8
Convert your date string into an accepted date format:



See the following pages, they will be useful:
Date object,
Regular Expression (RegExp) object.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Bear Bibeault wrote:I hate dealing with dates with a passion. Can you use the date parsing utility function provided by the jQuery UI datepicker? If not, you might need to regex the string and reform it to something that Date() likes. Icky icky icky.


Perfect!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

I know I'm being an old fuddy-duddy, but is that code Y2K-compliant? Tom Varga's code wasn't... but perhaps you won't be expecting dates before 2000?
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Paul Clapham wrote:I know I'm being an old fuddy-duddy, but is that code Y2K-compliant? Tom Varga's code wasn't... but perhaps you won't be expecting dates before 2000?


I think anytime you go to a 2 digit year, Y2K goes out of the window. We're not expected to have any dates prior to 2000 though. We brought this up to the client.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JavaScript Date Formats and new Date()
 
Similar Threads
how do i get day of the week from the date
time stamp question
Inserting the Date in to MySQL
sysdate function
convert text object to date where date-format is dynamic