如果用c#把当前时间转化为Discuz中的posttime,也就是mysql中的时间戳Timestamp
2012-04-06 14:05
169 查看
public static int DateToTimestamp(DateTime date)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
int timestamp = (int)Math.Floor(diff.TotalSeconds);
return timestamp;
}
public static DateTime TimestampToDate(double timestamp)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime date = origin.AddSeconds(timestamp);
return date;
}
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
int timestamp = (int)Math.Floor(diff.TotalSeconds);
return timestamp;
}
public static DateTime TimestampToDate(double timestamp)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime date = origin.AddSeconds(timestamp);
return date;
}
相关文章推荐
- SQL Server时间粒度系列----第6节基于当前日的小时数和分钟数与mysql unix_timestamp和from_unixtime的mssql实现
- 怎样在MySQL中操作(当前时间CurrentTime)<![CDATA[<=]]>
- mysql timestamp 默认值当前时间
- mysql版本 5.6.10,UNIX_TIMESTAMP和FROM_UNIXTIME支持最大时间戳转换
- Mysql 设置datetime不能为当前时间,使用timestamp
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- Mysql日期时间类型(DATE,DATETIME,TIMESTAMP)和函数及与linux系统时间之间的转换(UNIX_TIMESTAMP、FROM_UNIXTIME)
- mysql建表一个timestamp类型字段会默认为当前时间,TIMESTAMP与DATETIME区别
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySQL 与 PHP 日期时间格式对比 UNIX_TIMESTAMP() / time() / strtotime()
- mysql 中 unix_timestamp,from_unixtime 时间戳函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- if you are not making someone else's life better, then you are wasting your time.– Will Smith如果你不能给别人的生活带来改善,那么你就是在浪费你的宝贵时间。 --威尔 史密斯(程序员,你做的东西...)
- mysql中TIMESTAMP设置默认时间为当前时间
- JAVA获得UUID、获得当前时间(年月日,并转化为数据库存储的Timestamp、String格式)
- mysql所支持的日期时间类型有:DATETIME、 TIMESTAMP、DATE、TIME、YEAR。
- from_unixtime/unix_timestamp mysql时间操作
- mysql 5.6 时间函数的变化 FROM_UNIXTIME CURRENT_TIMESTAMP