Skip to main content

Timeline for Get date and time in .NET

Current License: CC BY-SA 3.0

16 events
when toggle format what by license comment
Jan 29, 2013 at 20:19 history edited Peter Mortensen CC BY-SA 3.0
(Ref. <http://www.irosetta.com/questions/4cc5113f19ce9518da000248/answers/4cc5113f19ce9518da000249>.)
Mar 10, 2012 at 10:58 comment added Vishwanath Dalvi @rizwanShahid Because he is Jon Skeet.
Mar 9, 2012 at 8:03 vote accept Mulesoft Developer
Mar 9, 2012 at 7:35 comment added Øyvind Bråthen @rizwanShahid: Actually, Jon's solution is more correct than mine, since it takes care of "glitches" that might occur it the time goes from XX:59 to XX+1:00 between the call to get the hour and get the minute, and it most definitly works.
Mar 9, 2012 at 7:35 comment added Jon Skeet @rizwanShahid: I've edited my post with a short but complete program. Please run that code - if that prints 0 0 and it's not midnight in your time zone, I'll eat my hat...
Mar 9, 2012 at 7:33 history edited Jon Skeet CC BY-SA 3.0
added 911 characters in body
Mar 9, 2012 at 7:32 comment added Christian.K @rizwanShahid Since "Øyvind Knobloch-Bråthen" solution works for you and Jon's does "not", it seems you really just need to pay attention to the fact that Jon named the variables without the "current" in front of them. Also see "Botz3000" comment above.
Mar 9, 2012 at 7:30 comment added Jon Skeet @rizwanShahid: That's simply wrong. Perhaps you printed currentHour and currentMinute, which were still using your old code. I'll include a short but complete example, to prove it works. Really, I know what I'm talking about here. Note that the answer you do like is flawed, for reasons I've explained in my answer.
Mar 9, 2012 at 7:26 comment added Mulesoft Developer I just did copy and paste your code and verify it but it gives me the same result 0,0
Mar 9, 2012 at 7:25 comment added Botz3000 why doesn't it work? did you forget to replace "hour" with "currentHour" and "minute" with "currentMin" so that it works with your code? almost seems like it.
Mar 9, 2012 at 7:25 comment added Jon Skeet @rizwanShahid: I'm giving the right answer. Really, I am. And you claiming it doesn't work without giving any indication of what you're seeing when you try my code doesn't help. (I've just double-checked it myself, and it gave me 7 for the hour, and 27 for the minute... both of which are correct for my local time. What did you see when you tried it?)
Mar 9, 2012 at 7:24 history edited Jon Skeet CC BY-SA 3.0
added 56 characters in body
Mar 9, 2012 at 7:23 comment added Mulesoft Developer Without confirmation how people start giving you +1 although you are giving wrong answer.
Mar 9, 2012 at 7:23 comment added V4Vendetta @rizwanShahid i think you are using DateTime.Today instead of DateTime.Now
Mar 9, 2012 at 7:21 comment added gideon @rizwanShahid it does. I just checked with my compiler.
Mar 9, 2012 at 7:18 history answered Jon Skeet CC BY-SA 3.0