gettime.awk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # getlocaltime.awk --- get the time of day in a usable format
  2. #
  3. # Arnold Robbins, arnold@skeeve.com, Public Domain, May 1993
  4. #
  5. # Returns a string in the format of output of date(1)
  6. # Populates the array argument time with individual values:
  7. # time["second"] -- seconds (0 - 59)
  8. # time["minute"] -- minutes (0 - 59)
  9. # time["hour"] -- hours (0 - 23)
  10. # time["althour"] -- hours (0 - 12)
  11. # time["monthday"] -- day of month (1 - 31)
  12. # time["month"] -- month of year (1 - 12)
  13. # time["monthname"] -- name of the month
  14. # time["shortmonth"] -- short name of the month
  15. # time["year"] -- year modulo 100 (0 - 99)
  16. # time["fullyear"] -- full year
  17. # time["weekday"] -- day of week (Sunday = 0)
  18. # time["altweekday"] -- day of week (Monday = 0)
  19. # time["dayname"] -- name of weekday
  20. # time["shortdayname"] -- short name of weekday
  21. # time["yearday"] -- day of year (0 - 365)
  22. # time["timezone"] -- abbreviation of timezone name
  23. # time["ampm"] -- AM or PM designation
  24. # time["weeknum"] -- week number, Sunday first day
  25. # time["altweeknum"] -- week number, Monday first day
  26. function getlocaltime(time, ret, now, i)
  27. {
  28. # get time once, avoids unnecessary system calls
  29. now = systime()
  30. # return date(1)-style output
  31. ret = strftime("%a %b %e %H:%M:%S %Z %Y", now)
  32. # clear out target array
  33. delete time
  34. # fill in values, force numeric values to be
  35. # numeric by adding 0
  36. time["second"] = strftime("%S", now) + 0
  37. time["minute"] = strftime("%M", now) + 0
  38. time["hour"] = strftime("%H", now) + 0
  39. time["althour"] = strftime("%I", now) + 0
  40. time["monthday"] = strftime("%d", now) + 0
  41. time["month"] = strftime("%m", now) + 0
  42. time["monthname"] = strftime("%B", now)
  43. time["shortmonth"] = strftime("%b", now)
  44. time["year"] = strftime("%y", now) + 0
  45. time["fullyear"] = strftime("%Y", now) + 0
  46. time["weekday"] = strftime("%w", now) + 0
  47. time["altweekday"] = strftime("%u", now) + 0
  48. time["dayname"] = strftime("%A", now)
  49. time["shortdayname"] = strftime("%a", now)
  50. time["yearday"] = strftime("%j", now) + 0
  51. time["timezone"] = strftime("%Z", now)
  52. time["ampm"] = strftime("%p", now)
  53. time["weeknum"] = strftime("%U", now) + 0
  54. time["altweeknum"] = strftime("%W", now) + 0
  55. return ret
  56. }