---
title: "How to parse string contains time of day in c#?"  
description: "How to parse string contains time of day in c#?"  
author: "Anonymous User"  
published: 2014-11-10  
updated: 2014-11-11  
canonical: https://www.mindstick.com/forum/2555/how-to-parse-string-contains-time-of-day-in-c-sharp  
category: "asp.net"  
tags: ["c#", "exception", "time", "datetime"]  
reading_time: 1 minute  

---

# How to parse string contains time of day in c#?

I try to [cast](https://answers.mindstick.com/qa/97273/how-to-cast-a-baitcaster) a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) to time span but i get the following [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) :

[Input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) string was not in a [correct format](https://www.mindstick.com/forum/72/input-string-was-not-in-a-correct-format).

My [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) :

rad_from_time.SelectedTime = TimeSpan.Parse(pro[0].FromTime)

pro[0].FromTime = "1:00 AM";

## Replies

### Reply by Manoj Bhatt

Try this:

rad_from_time.SelectedTime = DateTime.ParseExact(pro[0].FromTime, "h:mm tt", CultureInfo.InvariantCulture).TimeOfDay;


---

Original Source: https://www.mindstick.com/forum/2555/how-to-parse-string-contains-time-of-day-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
