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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:47:01+00:00 2026-05-11T11:47:01+00:00

I am receiving data representing a time slot from a service as a string

  • 0

I am receiving data representing a time slot from a service as a string in the form of:

1500-1600

This meaning 3pm to 4pm.

I will have a list of these e.g.

1200-1300

1300-1400

1400-1500

and I have to represent this in the UI as

12pm – 1pm

1pm – 2pm

2pm – 3pm

Unfortunately this list could be in a random order.

My question is is there any way of using the DateTime object to be able to convert a 24 hour time to a 12 hour time and also is there a way of ordering times in order?

At the moment I am feeling I will have to write a custom parsing function but wondering if anyone knows how to do this better? or could advise on how they would achieve this.

  • 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. 2026-05-11T11:47:01+00:00Added an answer on May 11, 2026 at 11:47 am

    If you have the four digit strings (1200, 1300) and it will always be four digits (e.g. 9 am is 0900) then you can call the static ParseExact method on the DateTime structure like so:

    DateTime dt = DateTime.ParseExact(time, 'HHmm', formatInfo); 

    formatInfo is an IFormatProvider interface implementation.

    If you have a three digit string, then you can use this:

    DateTime dt = DateTime.ParseExact(time, 'Hmm', formatInfo); 

    However, I would recommend using a four-digit string because of the ambiguity presented with a time like ‘121’.

    From there, if you want to output am/pm, etc, etc, you would just call the ToString method, passing the following format:

    string ampm = dt.ToString('htt'); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 229k
  • Answers 229k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Add a reference to System.Data.Entity.dll, which contains the System.Data.Mapping namespace. May 13, 2026 at 1:44 am
  • Editorial Team
    Editorial Team added an answer Check out Will HTML5 be SQL-free? and DOM Storage: a… May 13, 2026 at 1:44 am
  • Editorial Team
    Editorial Team added an answer I think what you're looking for here is: function getGallery($id){… May 13, 2026 at 1:44 am

Related Questions

I am receiving data which I am basically recreating the image of a check
I am trying to chop XML data into usable strings to reuse them later
I'm currently having trouble creating an image from a binary string of data in
I'm talking to a DDE server I don't have very much documentation for using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.