I have a datetime string.  How do I format it for output?

Posted on 2011-10-14
Last Modified: 2012-05-12
Hey guys.  I thought this should be an easy one but its turning out not to be.  

This is my issue in its most basic form:  I want to write raw HTML so that when I open that HTML my predefined datetime is output based on a format I also have defined.

So for example, lets say my datetime string is 2011-08-13 10:15:39.000.

When I load my page into IE, I want the page to show 10:15.

Thats it.  I was expecting to find something like what we have for numbers.  I was expecting this would/should work:  <format:"hh:mm">2011-08-13 10:15:39.000</format> but obviously it doesn't.

So how do I do it?  Thanks!
Question by:JasonWilliam
    LVL 82

    Expert Comment

    by:Dave Baldwin
    HTML will not modify any data you give it.  You can use HTML to change the appearance but not the content.  If you can use javascript, you can use it to extract a 'substring' from the date string.

    Author Comment

    Ok I understand.

    Let me ask this then:  If I'm relegated to using Javascript to get this done, is there a more efficient way of formatting my datestring?  Seems like javascript would have to have some datetime format function that will accept my datestime string?

    The end game here is to support a variable datetime format.  My user is going to give me a format string, and I'm going to output the datetime (from another source) in the fomat they've specified.

    LVL 82

    Accepted Solution

    The javascript Date functions are mostly about getting a date from the local system and displaying it.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now