Click here to Skip to main content
11,409,801 members (53,747 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
Iam trying to display only 'time' from DateTime.So that my gridview will looks simpler.Because I have to display it in the aspx page.I tried some but they are not working.

DateTime.Parse(DateTime.Now.ToString("hh:mm:ss"))

The code above is not working.Can anyone suggest a better way?
Posted 1-Jan-13 2:06am
danil33399
Edited 1-Jan-13 2:14am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Try this:
string time = DateTime.Now.ToLongTimeString();
Hope this helps.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string time = DateTime.Now.TimeOfDay.ToString();
  Permalink  
v2
Comments
danil33 at 1-Jan-13 7:28am
   
Now also date is showing.I don't know what is the problem.

I'll copy that code completely

ConsumptionGrid.DataSource = Utilities._dbManager.GetConsumptionlist(PageIndex,
Const.NumberOfItemsPerPage,
_consumer.MeterNumber,
DateTime.Parse(DateTime.Now.ToLongTimeString()));
ConsumptionGrid.DataBind();
danil33 at 1-Jan-13 23:58pm
   
Hi,
I parsed it because it is showing Error:Argument type 'string' is not assignable to parameter type 'System.DateTime'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

do you want something like this
DateTime.Now.ToString("hh:mm:ss")
  Permalink  
Comments
danil33 at 1-Jan-13 7:47am
   
Hi Satish,
I tried this but again it is giving both date and time.
satishgv1985 at 1-Jan-13 8:09am
   
I just tried this
DateTime.Now.ToString("hh:mm:ss")
in my LinqPad and I got
06:37:53
post your code for more details
satishgv1985 at 1-Jan-13 8:10am
   
one more, have you used any formatting options in your aspx code. Post that code as well to see indetail
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi,

Try this :-
a) Long time pattern
DateTime.Now.ToString("T")
 
b) Short time pattern
DateTime.Now.ToString("t")
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this.
DateTime Time = DateTime.Now;
Time.ToString("h tt");
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 270
1 OriginalGriff 255
2 Maciej Los 138
3 Andy Lanng 105
4 Sascha Lefévre 95
0 Sergey Alexandrovich Kryukov 8,771
1 OriginalGriff 6,905
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100