1

Dates are always a kick in the nuts (at least for me) and I faced the fact that Javascript doesn't seem to have a method to format dates.

I'm trying to format a date to use the Google API which ask you for a date in this format: yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff (e.g. 2011-06-25T10:00:00.000+02:00)

I need to be able to read that kind of string and to produce one.

1 Answer 1

1

I often use jQuery plugin: http://plugins.jquery.com/project/jquery-dateFormat

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="https://raw.github.com/phstc/jquery-dateFormat/master/jquery.dateFormat-1.0.js"></script>
<script type="text/javascript">
$(function() {
    var d = new Date();
    alert($.format.date(d, 'yyyy-MM-ddTHH:mm:ss'));
})
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Yaiks! it works for query purpouses it's sad that doesn't support to convert dates from YYYY-MM-DD to DD-MM-YYYY doesn't it?
Do it yourself, it's two lines of code, or one if you use a regular expression: '2011-03-21'.replace(/(\d{4})-(\d\d)-(\d\d)/, '$3-$2-$1').
Sorry for the late question on this answer - I have the script loaded, but always get JavaScript runtime error: Object doesn't support property or method 'date' when I try to call var msgTime = $.format.date(message[0].ActionMessageDt.toString(), "MM-dd-yyyy HH:mm:ss");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.