0

I am having an issue with Javascript right now and a plugin named "JMonthCalendar". The problem is essentially that using the "Date(2011, 6, 6) will return information like this: "Wed Jul 06 2011 00:00:00 GMT-0500 (Central Daylight Time)". This will not work, the plugin does not read this format.

I then tried to look up timestamps, but this is not what I want either: "1311742800000"

What I need is something like this: "2011-06-28T00:00:00.0000000"

Is there a pre-programmed function for this? If not, how would you propose that I could best do it?

Thank you for your help.

EDIT: Here is the website and page that is in question, I am testing it right now so if it seems odd, thats why. -- http://powerqualityuniversity.net/?d=registration&p=calendar

1 Answer 1

1

Try this:

<script type="text/javascript">

function leadingZero(number) {
    return number < 10 ? "0" + number : number;
}

function formatDate(date) {
    return date.getFullYear() + "-" + 
        leadingZero(date.getMonth()) + "-"+
        leadingZero(date.getDate()) + "T" + 
        leadingZero(date.getHours()) + ":" + 
        leadingZero(date.getMinutes()) + ":" +
        leadingZero(date.getSeconds());
}

alert("formatted date: " + formatDate(new Date(2011, 6, 6)));

</script>

It might not be the sexiest solution, but since Javascript afaik doesn't have any native date formatting functionality built in you need to implement them yourself.

Sign up to request clarification or add additional context in comments.

3 Comments

There is something not quite right with this. The day is always half. So lets say you are scheduling something on the 6th, and but it actually becomes the 3rd. Now, I checked to see if it was the calendar or not, but it is the script, which makes it incredibly odd because yours ought to work, shouldn't it?
Sorry, I fixed it. I changed getDay() to getDate(). getDay actually returns the day of the week. Try the code now.
Perfect! I agree, it isn't very "sexy", but it works. Thank you very much, my brain is fried today and work can't stop for fried brains.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.