How to get Hours and Minutes as two digits with leading zero from DateTime object?
beginer
1328
Points
43
Posts
|
How to get Hours and Minutes as two digits with leading zero from DateTime object? I'm trying following code formulate the file path:
But it's not returning always two digits from hours, minutes, etc. I want path like "2021/04/07/02/04"
Use .ToString() i.e. for hour use DateTime.UtcNow.ToString("HH"); - Rahul Maurya 09-Apr-2021 01:57
|
Answers
Rashmi
820
Points
17
Posts
|
Using hh will do a leading 0. Same with mm for minutes will do a leading zero. If you want seconds, you can use ss.
You can refer to DateTime.ToString()
Posted On:
10-Apr-2021 08:38
Thanks - beginer 17-Apr-2021 01:21
|