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 8571015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:41:24+00:00 2026-06-11T18:41:24+00:00

I need help converting this date format. Here are the date string I receive

  • 0

I need help converting this date format.
Here are the date string I receive from a server, it can be M/DD/YYYY or M/D/YYYY or MM/D/YYYY or MM/DD/YYYY.

EDIT: Sorry, my bad. After the format above, there is additional string of time HH:MM:SS AM so the complete string I receive will be M/D/YYYY HH:MM:SS AM

My problem now is I use String.substring(x, y) to extract the date, month, and year.

So far I only managed to determine the location of “/” but I’m still thinking how to use it in the substring method.

var separators = [];
for(var b = 0, c = String.length; b < c; b++){
    if(String[b] === '/'){
        separators.push(b);
    }
}

I’m confused how to extract the date and month dynamically and then pad “0” in front of the single digit number, so I appreciate any helps. Thank you 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-06-11T18:41:25+00:00Added an answer on June 11, 2026 at 6:41 pm
    var dt = "10/6/2012 12:34:56 AM".split(' '); 
    dt = dt[0].split('/'); 
    
    // dt[0] => month
    // dt[1] => day
    // dt[2] => year
    

    it works with any of the above format – M/DD/YYYY or M/D/YYYY or MM/D/YYYY or MM/DD/YYYY – (and it’s easier than using substring)

    then to add a pad to month and day just use slice() like so

    dt[0] = ("0"+ dt[0]).slice(-2);
    dt[1] = ("0"+ dt[1]).slice(-2);
    

    and to get a padded data just re-join the array parts

    dt = dt.join('/');
    

    Example jsbin : http://jsbin.com/exodos/2/edit

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

Sidebar

Related Questions

Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I need help converting a DATE format to STRING format. I have a variable
I need help converting this string --> 20090727 10:16:36:643 to --> 07/27/2009 10:16:36 The
I need help converting this into PHP: Public Function Encrypt(ByVal text As String) As
I need help converting this SQL statement, into EF4: Select Posts.PostID, Post, Comment from
I need help converting this code from C# to Java. public static ulong GetChecksum(byte[]
I need help converting a VB.NET handles statement to C#. This is the VB
I need help converting a string to double with 7 decimals. I have a
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Can someone please help with converting this code to plain JS: $(document).ready(function() { $(textarea).bind(keydown,

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.