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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:29:28+00:00 2026-05-22T11:29:28+00:00

I am getting the current time and trying to split it into two separate

  • 0

I am getting the current time and trying to split it into two separate variables.
I want the time to be in 12 hours not 24

When i do this the first and second variable are the same. How can i fix this?

int hour = DateTime.Now.Hour % 12;
if (hour == 0) hour = 12;

then,

FirstDigitHour = hour / 10;
secondDigitHour = hour %  10;

the time here is 6 pm so FirstDigitHour & secondDigitHour both = 6

the first digit should equal 0

  • 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-22T11:29:28+00:00Added an answer on May 22, 2026 at 11:29 am

    If you’re trying to format the time for display, I would advise you use the proper format string:

    DateTime.Now.ToString("hh tt")
    

    Which is the time in 2-digit 12-hour format (hh) with AM/PM (tt)

    See the documentation:
    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

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

Sidebar

Related Questions

i'm trying to get the current date and time formatted, this is my code:
I'm trying to extract boot time by getting current time SYSTEMTIME structure, then converting
Can anyone help me getting started with this? We have a current keygen for
I'm trying to access the current hibernate session in a test case, and getting
I'm trying to use the DateTime class to output the current time in DateTime::ATOM
I've searching forever trying to figure out why IE will not save the current
I'm trying to consume a WebService for getting the current Weather for places in
I have been trying to play around with this for a long time and
Without getting into all of the gory details, I am trying to design a
I am getting this error while trying to connect my web site. Unspecified error

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.