0

I can't seem to enter 12pm into the DateTime.

This is my Code:

string a = "00:00";
DateTime applyClock = DateTime.ParseExact(a, "H:mm", System.Globalization.CultureInfo.CurrentCulture);

The string has to be '00:00' (it will be a 24h format).

I tried everything I could think of in the DateTime.ParseExact. I tried "hh:mm", "H:mm", "HH:mm", "H:mm:ss"(format error). I read that "H:mm" or "HH:mm" should be the solution but still 'applyClock' is at 12 am instead of pm.

How can I have a string of "00:00" and put this time into 'applyClock' ? (01:00 and so on works fine)

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
axbeit
  • 853
  • 11
  • 35
  • Do you just want `DateTime.Now.Date`? _"The string has to be '00:00' (it will be a 24h format)."_ - also note that `DateTime` objects do not have a human-readable representation stored in them, so any human-readable date you see is a (thread) culture-sensitive conversion to a string. – ProgrammingLlama May 21 '19 at 08:08
  • 12:00 is 12pm (midday), 00:00 is 12am (midnight) – phuzi May 21 '19 at 08:08
  • @phuzi I just entered "string a = "12:00" - It is 12 am. – axbeit May 21 '19 at 08:09
  • 1
    Did you use the "HH:mm" format? – phuzi May 21 '19 at 08:10
  • @phuzi yes I also have tried using "HH:mm" – axbeit May 21 '19 at 08:10
  • @axbeit If `DateTime.Now.Date` isn't what you need, please can you tell me why? I might be misunderstanding what you're trying to achieve. – ProgrammingLlama May 21 '19 at 08:11
  • 1
    if I do `DateTime.ParseExact("00:00", "HH:mm", System.Globalization.CultureInfo.CurrentCulture)` then I get 21/05/2019 00:00:00 which is 12 am today. Not sure why you see 12pm! – phuzi May 21 '19 at 08:12
  • @Clint Have seen it. Have tried it. applyClock still shows "12 am" instead of "12 pm". – axbeit May 21 '19 at 08:13
  • 1
    you are doing it right! but 00:00 in 24h format is 12:00 am (midnight) and 12:00 is 12:00 (midday) – Badwi Finianos May 21 '19 at 08:14
  • @John I want to have a string that contains "00:00" in it. I want to apply this time into 'applyClock' so 'applyClock' has "12 pm" as it's time. But for some reason 'applyClock' time is 12 am if my string is "00:00" – axbeit May 21 '19 at 08:15
  • 1) As I explained before, `DateTime` doesn't contain a string value. `DateTime` also _always_ has a time component, since the entire date and time is internally represented by a single `long` value. 2) 00:00 _is_ 12am (i.e. the time when most people might be in bed asleep, not the time you eat lunch). – ProgrammingLlama May 21 '19 at 08:16
  • 1
    That's wrong though 00:00 is 12 ___am___ not 12 ___pm___ – phuzi May 21 '19 at 08:16
  • 1
    @axbeit then you're doing something non-standard; 00:00 in all time formats is *always* 12 AM (midnight), never 12 PM (noon) – Clint May 21 '19 at 08:16
  • I see my problem. I'm stupid. Sorry. Thanks for the help. In my mind I had 12 pm as midnight, which is wrong obviously. – axbeit May 21 '19 at 08:19
  • 1
    @axbeit No worries :) – ProgrammingLlama May 21 '19 at 08:21
  • 2
    You shouldn't be so hard on yourself, I wouldn't say you're stupid, we've all been there and stared with our blind eyes at something, not seeing the problem even though it was easy to spot all along. – Lasse V. Karlsen May 21 '19 at 09:14

0 Answers0