Click here to Skip to main content
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 450
1 OriginalGriff 230
2 DamithSL 150
3 Dave Kreskowiak 120
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,740
1 DamithSL 5,644
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,011
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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