]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Scripts/GetUtcDateTime.py
BaseTools: Fixed build failure when using python38
[mirror_edk2.git] / BaseTools / Scripts / GetUtcDateTime.py
CommitLineData
caa7d3a8
CC
1## @file\r
2# Get current UTC date and time information and output as ascii code.\r
3#\r
4# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# SPDX-License-Identifier: BSD-2-Clause-Patent\r
7#\r
8\r
9VersionNumber = '0.1'\r
10import sys\r
11import datetime\r
12import argparse\r
13\r
14def Main():\r
15 PARSER = argparse.ArgumentParser(\r
16 description='Retrieves UTC date and time information (output ordering: year, date, time) - Version ' + VersionNumber)\r
17 PARSER.add_argument('--year',\r
18 action='store_true',\r
19 help='Return UTC year of now. [Example output (2019): 39313032]')\r
20 PARSER.add_argument('--date',\r
21 action='store_true',\r
22 help='Return UTC date MMDD of now. [Example output (7th August): 37303830]')\r
23 PARSER.add_argument('--time',\r
24 action='store_true',\r
25 help='Return 24-hour-format UTC time HHMM of now. [Example output (14:25): 35323431]')\r
26\r
27 ARGS = PARSER.parse_args()\r
28 if len(sys.argv) == 1:\r
29 print ("ERROR: At least one argument is required!\n")\r
30 PARSER.print_help()\r
31\r
32 today = datetime.datetime.utcnow()\r
33 if ARGS.year:\r
34 ReversedNumber = str(today.year)[::-1]\r
35 print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
36 if ARGS.date:\r
37 ReversedNumber = str(today.strftime("%m%d"))[::-1]\r
38 print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
39 if ARGS.time:\r
40 ReversedNumber = str(today.strftime("%H%M"))[::-1]\r
41 print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
42\r
43if __name__ == '__main__':\r
44 Main()\r