GetUtcDateTime.py 1.7 KB

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