Convert time to HH:mm format

  • Thread starter Thread starter Vamshi K J
  • Start date Start date
V

Vamshi K J

Guest
Hi Team,


App.Config file key:


<add key="ProcessTimeInterval" value="14:30"/> <!--Process Time Interval is in HH:mm in 24 hour time format-->



Class file code:


var ProcessDateTime = DateTime.ParseExact(ConfigurationValues.ProcessTimeInterval, "HH:mm", null, System.Globalization.DateTimeStyles.None);


I have a config key with excepted time format is "HH:mm". I am facing issues at var ProcessDateTime when the config key value is

Example:
<add key="ProcessTimeInterval" value="7:30"/>
<add key="ProcessTimeInterval" value="7:3"/>
<add key="ProcessTimeInterval" value="7"/>


Need inputs to handle the below scenarios because the below time format is not in "HH:mm".

1) when the config key value is "7:30" format THEN convert the "7:30" to "07:30" in the class file code to make it to "HH:mm" format.

2) when the config key value is "7:3" format THEN convert the "7:3" to "07:03" in the class file code to make it to "HH:mm" format.

3) when the config key value is "7" format THEN convert the "7" to "07:00" in the class file code to make it to "HH:mm" format.





Vamshi Janagama

Continue reading...
 
Back
Top