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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:32:28+00:00 2026-05-16T21:32:28+00:00

I need to parse dates and times from strings. The Problem is that the

  • 0

I need to parse dates and times from strings. The Problem is that the strings can have any possible format. But I also get the format strings.

So i get:

Date = "9/15/2010"
Time = "16:12:45"
DateFormat = "M/dd/yyyy"
TimeFormat = "h:mm:ss"
TimeZone = "+2:00:00"  // +/- and time in TimeFormat

But i have some problems parsing these strings.

I can’t parse the time

DateTime.ParseExact("16:12:45","h:mm:ss",null,DateTimeStyles.None);

does not work and causes a FormatException. What is wrong with this call?

If the DateFormat contains slashes, i need to escape them @"M\/dd\/yyyy". Are there any other chars that would need escaping?

Can i parse the whole DateTime in one? Somehting like:

DateTime.ParseExact(Date+' '+Time+' '+TimeZone,DateFormat+' '+TimeFormat+' +'+TimeFormat,null,DateTimeStyles.None);
  • 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-16T21:32:28+00:00Added an answer on May 16, 2026 at 9:32 pm

    What is wrong with this call?

    The “h:mm:ss” format string expects the hours element to be in 12-hour format (h); The hours in your string are in 24-hour format so you need to use H instead:

    DateTime.ParseExact("16:12:45", "H:mm:ss", null, DateTimeStyles.None);
    

    Are there any other chars that would need escaping?

    Any literal character in your string that clashes with a format specifier will need to be escaped. For example, / is the date separator but \/ means the literal / character; : is the time separator but \: means the literal : character; y is one of the year specifiers but \y is the literal y character.

    Can i parse the whole DateTime in one?

    Yes.

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

Sidebar

Related Questions

I have a website where I need to parse date/time strings from receipts. These
I am getting some response from server side which i need to parse but
I have string of format 01-Jan-11 and I need to parse it to a
I have to use some dates and times from a legacy database. They are
Is it possible to convert date strings from one format to another without actually
Need to parse a file for lines of data that start with this pattern
i need to parse simple JSON php in my tableview for that i searched
I need to parse/extract information from an html page. Basically what I'm doing is
How can I parse a string that represents a date and/or time using iPhone
I have the following data that basically I only need a few bits of

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.