如何将
例如,我有这样的 UUID:
如何将此转换为日期格式?我尝试了。
UUID
转换为日期格式 2011-04-22
?例如,我有这样的 UUID:
118ffe80-466b-11e1-b5a5-5732cf729524.
如何将此转换为日期格式?我尝试了。
String uuid="118ffe80-466b-11e1-b5a5-5732cf729524";
UUID uid = UUID.fromString(uuid);
long ls=convertTime(uid.timeStamp()); // it returns long value
public String convertTime(long time){
System.out.println("====="+time);
Date date = new Date(time);
Format format = new SimpleDateFormat("yyyy/MM/dd");
return format.format(date).toString();
}
我得到的输出结果是:4294744/11/02
同样的情况在Perl中运行良好。
$uuid='ef802820-46b3-11e2-bf3a-47ef6b3e28e2';
$uuid =~ s/-//g;
my $timelow = hex substr( $uuid, 2 * 0, 2 * 4 );
my $timemid = hex substr( $uuid, 2 * 4, 2 * 2 );
my $version = hex substr( $uuid, 2 * 6, 1 );
my $timehi = hex substr( $uuid, 2 * 6 + 1, 2 * 2 - 1 );
my $time = ( $timehi * ( 2**16 ) + $timemid ) * ( 2**32 ) + $timelow;
my $epoc = int( $time / 10000000 ) - 12219292800;
my $nano = $time - int( $time / 10000000 ) * 10000000;
#$time_date = scalar localtime $epoc;
#print strftime( '%d-%m-%Y %H:%M:%S', localtime($epoc) );
#print "\n Time: ", scalar localtime $epoc, " +", $nano / 10000, "ms\n";
timeStamp()
返回自1582年10月15日午夜以来以100纳秒为单位测量的时间戳;Date(long date)
期望接受自1970年1月1日00:00:00 GMT以来的毫秒数。因此,您需要将一种格式转换为另一种格式。 - tmuguet