如何从 unix 时间戳 decimal(16,4) 获取日、月和年

How to get day, month and year from unix timestamp decimal(16,4)

我想从由 Contact Form 7 to Database Extension Wordpress plugin 写入 MySQL 数据库的 decimal(16,4) 格式的 unix 时间戳中分别获取日、月和年。

我需要在 JAVA 完成!

例如,我想解析 1379446159.0400 (2013-09-17 19:29:19 +00:00),但我不知道该怎么做。

希望这对您有所帮助:

SELECT from_unixtime('1379446159.0400 ', '%Y %D %M %h:%i:%s') as time

如果你忽略特殊时间戳的小数部分,那么你可以这样做:

$ds=1379446159.0400;
list( $ts,$junk )=explode( '.',$ds);

$year=date( 'Y', $ts );
$month=date( 'm', $ts);
$day=date( 'd', $ts );

好的,谢谢大家尽管我的问题不够具体,但还是尽力帮助我。

我找到了解决方案 here 并像这样实施它:

long unixSeconds = Long.valueOf(submit_time.substring(0,10)).longValue();
Date date = new Date(unixSeconds*1000L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String formattedDate = sdf.format(date);
String timestampYear = formattedDate.substring(1,4);
String timestampMonth = formattedDate.substring(6,7);
String timestampDay = formattedDate.substring(9,10);

所以,我忽略了最后四位数字,猜测它是合法的。