Reputation: 55
How do I use only hours from DateTime.Now.ToString()
for setting a value (eg: a price) for two or more intervals?
I want to set a variable p
differently for every 5 hours.
Upvotes: 2
Views: 2332
Reputation:
Here is how you covert to string. If you want both methods, either work. https://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx
System.DateTime currentTime = System.DateTime.Now
int t = currentTime.Hour
string s = convert.toString(t)
s
This is another way of doing it as well
string time = currentTime.ToShortTimeString()
Upvotes: 1