简体   繁体   中英

Is Unix time the value of a MYSQL timestamp data type? Correct code example to convert from C#?

I found this sample source code for C# from How to convert a Unix timestamp to DateTime and vice versa? :

DateTime date = new DateTime(2011, 4, 1, 12, 0, 0, 0);

DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);

TimeSpan span = (date - epoch);

double unixTime =span.TotalSeconds.Dump();

If I was to insert into a MYSQL table the value of unixTime, would this be equivalent of a MYSQL timestamp datatype value? I just want to confirm this.

It depends on the version of MySQL. TIMESTAMP field format has been changed from unixtime to dd-mm-yyyy hh:mm:ss from 5.something. If you want to insert a unixtime into a timestamp field, you should use FROM_UNIXTIME() builtin.

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