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

Related Questions

I am receiving data from a web service and its replying me data in
I have a service which contains a Timer and TimerTask for receiving data from
I have a service which contains a Timer and TimerTask for receiving data from
I'm developing simple Windows Service sending and receiving data from remote web service. I
I have this problem.. I'm receiving data from a client..Using a socket connection. But
I am receiving data from a Web Service. The XML coming in is something
I am receiving data from a web service, and some of the strings have
I'm designing a system which is receiving data from a number of partners in
I have one thread that is receiving data over a socket like this: while
I am working on a small project that is receiving XML data in string

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.