|
@@ -0,0 +1,52 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: π
|
|
|
+ * @Description: 公司名转换
|
|
|
+ */
|
|
|
+public class ObjectId2Date extends UDF {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public String evaluate(String objectId) {
|
|
|
+ return toDateString(convertToDateFrom(objectId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Instant convertToInstantFrom(String objectId) {
|
|
|
+ return convertToDateFrom(objectId).toInstant();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Date convertToDateFrom(String objectId) {
|
|
|
+ return new Date(convertToTimestampFrom(objectId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static long convertToTimestampFrom(String objectId) {
|
|
|
+ return Long.parseLong(objectId.substring(0, 8), 16) * 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String toDateString(Date date) {
|
|
|
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
+ return dateFormat.format(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Stream.of("61bab6735c53fc56ba0ed815", "622ac651dae2eb5aa9510f18", "598ad932e4b0f0f169b42d5f")
|
|
|
+ .map(ObjectId2Date::convertToInstantFrom).forEach(System.out::println);
|
|
|
+
|
|
|
+ Stream.of("6220972eaaa0264735adc8cb", "622ac651dae2eb5aa9510f18", "598ad932e4b0f0f169b42d5f")
|
|
|
+ .map(x->new ObjectId2Date().evaluate(x)).forEach(System.out::println);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|