Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3223936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:09:53+00:00 2026-05-17T16:09:53+00:00

How I can format a date string using Javascript. For example: var date_str =

  • 0

How I can format a date string using Javascript. For example:

var date_str = "2010-10-06T03:39:41+0000";

The result should be like this:

11:39 AM Oct 6th

Is there any ideas on this? Note: date_str is an example of returned date from Facebook Graph API.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:09:54+00:00Added an answer on May 17, 2026 at 4:09 pm

    Parsing the date shouldn’t be too difficult – all the components are in the right order so you just need to split on the special characters, subtract 1 from the month value and apply the array, minus the last element, to Date.UTC():

    function parseDate(dStr) {
        var d    = dStr.split(/[-:T+]/); d[1] -= 1; d.pop();
        var date = new Date(Date.UTC.apply(Date, d));
    

    This gives us a Date object for the date specified, the rest is just formatting each component back into a string:

        // Declare an array of short month names
        var mon  = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov", "Dec"];
        // Determine between AM and PM
            ampm = date.getHours() > 12 ? "PM" : "AM",
    
        // Prepare for working out the date suffix
            nth  = date.getDate();
    
        // Date is nth for 11th, 12th and 13th
        if (nth >= 11 && nth <= 13)
            nth = "th";
        // Otherwise it's st, nd, rd, th if the date ends in 1, 2, 3 or anything else
        else
            nth  = ["", "st", "nd", "rd"][(nth+"").slice(-1)] || "th";
    
        // Return the string formatted date
        return (date.getHours() % 12) + ":" + (date.getMinutes()) + " " + ampm +
               " " + mon[date.getMonth()] + " " + date.getDate() + nth;
    }
    
    // Example:
    parseDate("2010-10-06T03:39:41+0000");
    // -> "4:39 AM Oct 6th" (in my timezone)
    

    If you want the output to be the same regardless of timezone (the original time supplied), you need to swap the methods getHours(), getMinutes(), etc for getUTCHours(), getUTCMinutes(), etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can brackets be escaped in using string.Format ? For example: String val =
How can I elegantly print the date in RFC822 format in Perl?
first time SO user :) I know that I can format a number like
Does anyone know how I can get a format string to use bankers rounding
I'm trying to figure out a way to format a date string that sits
Let's say I have a date that I can represent in a culture-invariant format
I am trying to set a javascript date so that it can be submitted
What is a culture-invariant way of constructing a string such that the Javascript Date()
When I am sending my date using .serialize() it is sending as an string
I have a string in this format dd.mm.yy (23.08.10). I would like to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.