Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

Display Time also beside this date.

It is displaying 15/10/2012

I need 15/10/2012 03:00 pm

This is my code.

C#
lblUpdate.Text = DateTime.UtcNow.Day.ToString() + "/" + DateTime.UtcNow.Month.ToString() + "/" + DateTime.UtcNow.Year.ToString();
Posted
Updated 14-Oct-12 23:03pm
v2
Comments
Karthik Harve 15-Oct-12 5:04am    
[Edit] added pre tags.
I.explore.code 15-Oct-12 5:07am    
you seriously don't know how to get time to display, even though you know how to display the Day, Month and Year?
_Amy 15-Oct-12 5:11am    
Why this much confusions in DateTime?
I have given the answers of all your DateTime questions. Go through it and check.

Try this:
C#
DateTime dt = (DateTime.UtcNow.Day, DateTime.UtcNow.Month, DateTime.UtcNow.Year, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second);
lblUpdate.Text = dt.ToString("dd/MM/yyyy hh:mm:ss tt").Replace('-', '/');

OR
C#
lblUpdate.Text = dt.ToString("dd/MM/yyyy hh:mm:ss tt");



Hope it helps!
--Amit
 
Share this answer
 
v2
Comments
ridoy 15-Oct-12 6:08am    
+5
_Amy 15-Oct-12 6:09am    
Thanks Ridoy! :)
C#
lblUpdate.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
 
Share this answer
 
Comments
ridoy 15-Oct-12 6:07am    
+5
C#
DateTime now = DateTime.Now;
console.WriteLine(now.ToString("g"));


you will get like 2/27/2009 12:12 PM
 
Share this answer
 
v2
Comments
ridoy 15-Oct-12 6:08am    
+5

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