Convert string date format to DateTime object

Welcome Forums General PowerShell Q&A Convert string date format to DateTime object

Viewing 4 reply threads
  • Author
    Posts
    • #256229
      Participant
      Topics: 1
      Replies: 3
      Points: 23
      Rank: Member

      How to convert time from string with format ‘Sunday, September 13, 2020 8:49:32 AM CDT‘ to DateTime object.

    • #256247
      Participant
      Topics: 5
      Replies: 330
      Points: 529
      Helping Hand
      Rank: Major Contributor
    • #256961
      Participant
      Topics: 1
      Replies: 3
      Points: 23
      Rank: Member

      But the time zone in string is in CDT domain, if get-date command is used time will be my system timezone.

      Would it be possible to get DateTime for ‘Sunday, September 13, 2020 8:49:32 AM CDT‘ (This is in CDT timezone) and get it converted to system timezone.

      • This reply was modified 1 week, 2 days ago by mach85.
    • #257012
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      You cannot capture time zone in this format (CDT, PDT, BST, etc.). You have to use an offset instead or do a time conversion with it stripped from the datetime string.

    • #257018
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero

      Here is one method:

      Timezones can be enumerated like so:

      Output:

Viewing 4 reply threads
  • You must be logged in to reply to this topic.