简体   繁体   中英

How to convert DB2 timestamp to datetime?

How do I convert a timestamp returned from DB2 ISeries to DateTime datatype in c#?

2012-07-06 09:52:50.926145

This did not worked for me

myEmployee.LastModified = Convert.ToDateTime(myRecord.GetString(myRecord.GetOrdinal("LASTMODIFIED")));

DateTime.Parse ?

DateTime result = DateTime.Parse("2012-07-06 09:52:50.926145");

It works, really.

You can do it with DateTime.TryParse()

DateTime date;
DateTime.TryParse("2012-07-06 09:52:50.926145", out date);

In your case

DateTime date,
DateTime.TryParse(myRecord.GetString(myRecord.GetOrdinal("LASTMODIFIED")), out date);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM