Converting a String to a TimeSpan using C#

Wondering how to convert to convert a String to a Timespan.. See below for an example snippet.

TimeSpan myTimeSpan = TimeSpan.Parse(myString);
(or)





TimeSpan myTimeSpan;
if (TimeSpan.TryParse(myString, out myTimeSpan))
{
      // Do something
}

or

var time = DateTime.ParseExact("17:00", "HH:mm", null).ToString("hh:mm tt");
returns 05:00 PM
DateTime.ParseExact is returning DateTime
Edited:
Include CultureInfo
var time = DateTime.ParseExact("17:00", "HH:mm", null).ToString("hh:mm tt", CultureInfo.GetCultureInfo("en-US"));
or
 
 
 
 
 

 

Comments

Popular posts from this blog

what is Event Cache table in sharepoint

CAML Query syntax and options in SharePoint

Change anchor link url in sharepoint calender