Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to conver date into
2017-09-06 15:36:38.613
in asp .net

I have It in following format

17-11-2017 13:59:00


What I have tried:

I Dont Idea about date conversion
Posted
Updated 16-Nov-17 22:04pm

First, convert it to a DateTime:
C#
DateTime dt;
if (!DateTime.TryParseExact(@"17-11-2017 13:59:00", "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
    {
    // Report problem to user
    return;
    }
(if you have it in a DateTime, you can skip this part)
Then use ToString to format it for presentation:
C#
string formatted = dt.ToString(@"yyyy-MM-dd HH:mm:ss.fff");
 
Share this answer
 
Comments
Graeme_Grant 17-Nov-17 4:05am    
Give a man a fish....
OriginalGriff 17-Nov-17 4:17am    
... teach a man to fish, and he will sit in a boat and drink beer all day. ;)
If you want to change the Date Format, then call StringFormat against the DateTime value passing a custom format. Here is the documentation (with code examples) on how to do it:

Custom Date and Time Format Strings | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900