Using C#, I have a datetime
object, but all I want is the hour and the minutes from it in a datetime object.
So for example: if I have a DateTime
object of July 1 2012 12:01:02
All I want is July 1 2012 12:01:00
in the datetime
object (so, no seconds).
To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.
DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25); Now, calculate the difference between two dates. TimeSpan ts = date2 - date1; To calculate minutes.
String hourMinute = DateTime. Now. ToString("HH:mm"); Now you will get the time in hour:minute format.
Try this:
var src = DateTime.Now; var hm = new DateTime(src.Year, src.Month, src.Day, src.Hour, src.Minute, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With