Browse Source

quick updates

control 7 tháng trước cách đây
mục cha
commit
3295713178
1 tập tin đã thay đổi với 35 bổ sung0 xóa
  1. 35 0
      scripts/convert-unixts

+ 35 - 0
scripts/convert-unixts

@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+
+# Converts Unix Timestamp to HKT
+
+import sys
+import datetime
+
+def safe_cast(string):
+    try:
+        return int(string)
+    except ValueError:
+        print(f'Error: "{string}" is not a valid integer!')
+        sys.exit()
+
+# Check for user input
+if len(sys.argv) < 2:
+    print('Usage: convert-unixts <Timestamp: int>')
+    sys.exit()
+
+# Check for timestamp format 
+raw_input = sys.argv[1]
+if len(raw_input) < 10:
+    print('Invalid timestamp format! Less than 10 digits.')
+    sys.exit()
+else:
+    timestamp = safe_cast(raw_input)
+
+# Convert to UTC
+utc_time = datetime.datetime.utcfromtimestamp(timestamp)
+
+# Convert to HKT (UTC+8)
+hkt_time = utc_time + datetime.timedelta(hours=8)
+
+# Print the result
+print("HKT:", hkt_time.strftime('%Y-%m-%d %H:%M:%S'))