繁体   English   中英

如何从Unix时间戳十进制(16,4)中获取日,月和年

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

我想分别以十进制(16,4)的格式与unix时间戳分开获取日期,月份和年份,该日期是通过联系表格7写入数据库扩展Wordpress插件写入MySQL数据库的。

我需要用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 );

好的,谢谢大家,尽管我提出的问题不够多,但仍努力为我提供帮助。

我在这里找到了解决方案并按以下方式实现了它:

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);

因此,我忽略了最后四位数字,认为它足够合法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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