0

It is a pretty simple problem but looking through most of the answers and MS documentation, I could not find a simple way to use the abbreviated timezone information from Unix system in ParseExact function of DateTime in Powershell v4.

The date value that I receive is like December 29, 2016 2:04:26 PM EST

All of the elements in above date time are easily mapped except the "EST". This can of course be EST, EDT, PST, PDT or any other timezone.

MS timezone seems to require the full time zone name or id. How do we lookup EST in MS timezone in powershell?

Update* We essentially decided to ignore the timezone since we are interested in the day not the specific time of the day. There does not seem to be a simple answer except adding a case or lookup type statement and then converting it to PS style timezone (-5:00) etc.

The question that was cited as duplicate was answered 9 years ago. PS has gone through many iterations in this period so it should be reasonable to ask this question for a simpler resolution.

sohail
  • 589
  • 1
  • 11
  • 26
  • No easy way: https://stackoverflow.com/questions/241789/parse-datetime-with-time-zone-of-form-pst-cest-utc-etc – beatcracker Oct 27 '17 at 20:43
  • I would see if you can change the way you receive the value. – Bill_Stewart Oct 27 '17 at 21:14
  • Its coming from key store details for a cert so I have very little control on that – sohail Oct 27 '17 at 21:44
  • What command is producing that output? – Bill_Stewart Oct 27 '17 at 21:54
  • 1
    what are you using this date value for? do you really need any granularity other than the day? if not, forget the timezone and round it downward to UTC always. – Kory Gill Oct 27 '17 at 21:58
  • Certificates will always have UTC-based timestamps internally. You are probably doing something along the way to convert it to a local time and to a string in that format. Instead of trying to figure out how to parse that format, try figuring out how to get the UTC time directly out of the key store. – Matt Johnson-Pint Oct 27 '17 at 22:02
  • @Matt Johnson, the question that was indicated as duplicate was answered in 2008 which is 9 years ago. The solution in the answer is not a simple answer. Since PS has gone through many iterations after that question, it should be valid to ask a similar question. – sohail Oct 30 '17 at 15:04
  • @Bill_Stewart, this output is coming from IBM's key management tool included in WebSphere – sohail Oct 30 '17 at 15:06
  • It's not about PowerShell. You cannot achieve this goal reliably in *any* language. Time zone abbreviations are not standardized, and often ambiguous. In many cases there simply is no abbreviation at all. – Matt Johnson-Pint Oct 30 '17 at 15:31
  • Please be more specific about the usage. Are you using the GUI or the `GSKCapiCmd` command line utility or something else? What options / operation are you performing? Ask about that in a new question. Asking about time zone abbreviations when you're trying to solve a key management issue is an XY problem. – Matt Johnson-Pint Oct 30 '17 at 15:38
  • Lets close this question. I used command line utility. I already mentioned in update to the question that we decided to ignore the timezone information. For me, it was important in Powershell because that's where we are processing certs from mutliple sources and IBM is just one of the many other sources. – sohail Oct 31 '17 at 16:34

0 Answers0