我是Perl语言的新手。如何将UUID
转换为日期格式2011-04-22
?
例如,我有像这样的UUID
118ffe80-466b-11e1-b5a5-5732cf729524
。
如何将此转换为日期格式?
答案 0 :(得分:4)
模块UUID::Tiny有一个名为time_of_UUID()的方法可能会有所帮助:
<强> time_of_UUID()强>
This function accepts UUIDs and UUID strings.
Returns the time as a floating point value, so use int()
to get a time() compatible value.
Returns undef if the UUID is not version 1.
my $uuid_time = time_of_UUID($uuid);
答案 1 :(得分:2)
也许这个javascript API可以帮助您将UUID转换为日期格式,
此API将UUID v1从1970-01-01转换为秒
<强> UUID_to_Date 强>
所有人都需要:
get_time_int = function (uuid_str) {
var uuid_arr = uuid_str.split( '-' ),
time_str = [
uuid_arr[ 2 ].substring( 1 ),
uuid_arr[ 1 ],
uuid_arr[ 0 ]
].join( '' );
return parseInt( time_str, 16 );
};
get_date_obj = function (uuid_str) {
var int_time = this.get_time_int( uuid_str ) - 122192928000000000,
int_millisec = Math.floor( int_time / 10000 );
return new Date( int_millisec );
};
var date_obj = get_date_obj( '8bf1aeb8-6b5b-11e4-95c0-001dba68c1f2' );
date_obj.toLocaleString( );// '11/13/2014, 9:06:06 PM'