Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to DateTime Format

I am getting a date and time from a data feed which I cannot change, and I need to convert it to a DateTime.

The format of the string is as follows.

timestamp="20131204T171054+0000"
like image 601
Ben Sharpe Avatar asked Feb 13 '26 10:02

Ben Sharpe


1 Answers

You could use DateTime.ParseExact and specify a Custom Date and Time Format String.

Your sample looks like "yyyyMMddTHHmmssK" might work.

In vb.net

Dim timestamp As String = "20131204T171054+0000"
Dim dt As DateTime = DateTime.ParseExact(timestamp, "yyyyMMddTHHmmssK", CultureInfo.InvariantCulture)

In C#

string timestamp = "20131204T171054+0000";
DateTime dt = DateTime.ParseExact(timestamp, "yyyyMMddTHHmmssK", CultureInfo.InvariantCulture);
like image 102
Joe Avatar answered Feb 17 '26 00:02

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!