How can convert this string yy-MM-dd HH:mm:ss.SSS to datetime in c#?
            Asked
            
        
        
            Active
            
        
            Viewed 9,547 times
        
    -1
            
            
        - 
                    3Minus one because this question shows no research effort on your part. Surely googling this would have been pretty easy... – rory.ap May 26 '16 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". – rory.ap May 26 '16 at 14:35
 
1 Answers
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.
        Rion Williams
        
- 74,820
 - 37
 - 200
 - 327
 
- 
                    
 - 
                    I've added [an example](https://dotnetfiddle.net/HYTE23) that you can use to test it out. – Rion Williams May 26 '16 at 14:40
 - 
                    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 . – Sezer Erdogan May 26 '16 at 14:44