niproblema
niproblema

Reputation: 101

Date.js formating to dd/mm/yyyy

Hello my user can input date like 2/2/2008, but I need it in format 02/02/2008. How do i reformat it with date.js?

I have tried:

document.getElementById("smth").value = Date.parse(smth, "dd/mm/yyyy").toString("dd/mm/yyyy");

while parse works fine, toString outputs 02/00/2008? and if run it again on date 02/00/2008 I get 01/00/2008.

Can anyone point me in right direction?

Upvotes: 0

Views: 955

Answers (2)

hijeane
hijeane

Reputation: 66

try to format with "dd/MM/yyyy"

Date.parse("2/2/2008", "dd/mm/yyyy").toString("dd/MM/yyyy")

Upvotes: 1

MeanGreen
MeanGreen

Reputation: 3305

Isn't this case sensitive? mm for minutes, MM for months?

Upvotes: 1

Related Questions