Click here to Skip to main content
12,953,743 members (53,588 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 1:06am
danil33399
Updated 1-Jan-13 1: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 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 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 1-Jan-13 7:47am
   
Hi Satish,
I tried this but again it is giving both date and time.
satishgv1985 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
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