Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello guys,
i want to develop a small application for windows. In this I want login time of the current user. By the help of a code I am able to get that also but the problem is that I am not able to understand the syntax. So can some plz tell me how to get the syntax in format of "DD/MM/YYYY HH:MM:SS AM/PM" ..
The above syntax is same as which i got by the method "DateTime.Now.ToString()" for current time of the system..

language --> C#
Posted

Try:
C#
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt");


From the online documentation [^]on Date and Time formatting:
tt: Displays the A.M./P.M. designator for the specified DateTime.
 
Share this answer
 
Comments
dixityashovardhan 11-Sep-10 15:27pm    
thanks sandeep.. but i am asking about how to get the "Current user Logged In time"..(not the current time of the system) in DD/MM/YYYY hh:mm:ss tt format.. plz explain how to get d user logged-in time..
It's difficult to advise when you haven't told us what it is you are trying to convert to "DD/MM/YYYY HH:MM:SS AM/PM" format.

If the login time came from WMI then it will be a string in Distributed Management Task Force (DMTF) format. In which case use the System.Management.ManagementDateTimeConverter class.

Alan.
 
Share this answer
 
This code should work:
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt");


However, the default DateTime.Now.ToString() format could be adjusted through your localization settings. If you change the locale of the current thread to "en-au" for example, you will get the above format with the AM/PM. Be careful with these formatting whenever you give it to an SQL insert/update
 
Share this answer
 

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