/    Sign up×
Community /Pin to ProfileBookmark

Date format – how?

hello, i have a JavaScript Calendar which picks date and inserts into FIELD..
and its format is : [B]3-4-2008 23:6:28[/B]

But i want to change it to: [B]2008-04-25 21:08:25[/B]

how can i change this..

here is a bit of code where i think this must be changed, but i am realy 0 in JS..

[CODE]
// datetime format
function str2dt (str_datetime) {

if (!re_date.exec(str_datetime))
return alert(“Invalid Datetime format: “+ str_datetime);
return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
}
function dt2dtstr (dt_datetime) {
return (new String (
dt_datetime.getDate()+”-“+(dt_datetime.getMonth()+1)+”-“+dt_datetime.getFullYear()+” “));
}
function dt2tmstr (dt_datetime) {
return (new String (
dt_datetime.getHours()+”:”+dt_datetime.getMinutes()+”:”+dt_datetime.getSeconds()));
}

[/CODE]

thank you

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallApr 27.2008 — Slightly rearrange the second function like this to do what you want.

function dt2dtstr (dt_datetime) {
return (new String (
dt_datetime.getFullYear()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getDate()+" "));
}
Copy linkTweet thisAlerts:
@LogicOpinionauthorApr 28.2008 — i did it this way

function dt2dtstr (dt_datetime) {

return (new String (

dt_datetime.getFullYear()+"-"+(dt_datetime.getDate()+1)+"-"+dt_datetime.getMonth()+" "));

}

in IE it shows as i want but in FF it displays older format anyway!
Copy linkTweet thisAlerts:
@KorApr 28.2008 — Can we see the full code? Or a link to a test page?
×

Success!

Help @LogicOpinion spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...