Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
While installing operating system on our system first time, the date and time will be detected correctly based on the region, though the system is not connected to the internet. In the same way is there any possibility to write the same thing as a program in c#. I mean can anybody provide a sniplet to detect the date and time automatically based on the region.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Aug-11 3:17am    
Stop re-posting!
--SA

C#
DateTime now = dateTime.Now;


Presuming your system clock is set for correct local time and the appropriate time zone, that should be all you need.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-11 14:08pm    
I can imagine if OP is going to ask questions like that each time some basic functionality is needed.
My 5 anyway.
--SA
Sergey Alexandrovich Kryukov 5-Aug-11 3:26am    
John, I only paid attention to this when OP re-posted the question.
Look at this: "While installing operating system". OP is is installing the OS! With C#!
Did you see it?
Imaging the value of your answer to this person... :-)
--SA
If you are trying to get the date and time based on the culture, see here[^].
 
Share this answer
 
Comments
Espen Harlinn 3-Aug-11 18:49pm    
Reasonable deduction, my 5
Abhinav S 4-Aug-11 1:28am    
Thank you Espen.
Sergey Alexandrovich Kryukov 5-Aug-11 3:26am    
Hey guys, I only paid attention to this when OP re-posted the question.
Look at this: "While installing operating system". OP is is installing the OS! With C#!
Did you see it?
I can imagine... :-)
--SA
Abhinav S 5-Aug-11 4:11am    
No I missed that actually.
When you installed the OS, it got the date and time from the clock on the mother board of the computer which, I assume, had been set correctly during manufacture.

As JSOP says, you can now just access it simply through code.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Aug-11 3:28am    
Aha, during installation of OS -- using C#? Seriously?
(I did not vote though, just for a record.)
--SA
_Maxxx_ 5-Aug-11 8:50am    
No- he asks if it is possible to do the same thing in c# - presumably he means getting the correct date and time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900