0

How can convert this string yy-MM-dd HH:mm:ss.SSS to datetime in c#?

2
  • 3
    Minus one because this question shows no research effort on your part. Surely googling this would have been pretty easy... Commented May 26, 2016 at 14:28
  • I didn't answer anything, and your comment doesn't make any sense. If you hover your cursor over the down-vote button, the first thing shown for a reason is "does not show any research effort". Commented May 26, 2016 at 14:35

1 Answer 1

5

You can use the DateTime.ParseExact() method and define the exact format string that you are expecting to receive :

// This will parse a DateTime object using the "yy-MM-dd HH:mm:ss.fff" format 
var date = DateTime.ParseExact(input,"yy-MM-dd HH:mm:ss.fff", null);

This assumes that the Y characters will represent a two-digit year and the S characters you were looking for would be considered fractional seconds, which have been converted to the y and f formats respectively.

Example

You can see a working example of this here.

Sign up to request clarification or add additional context in comments.

3 Comments

rion I will try your answer
I've added an example that you can use to test it out.
Thanks Rion.it is working fine.Some people dont enough read my question so he give me minus point .But you understand me correct so very thanks .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.