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: 24
      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: 349
      Points: 632
      Helping Hand
      Rank: Major Contributor
    • #256961
      Participant
      Topics: 1
      Replies: 3
      Points: 24
      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 4 months ago by mach85.
    • #257012
      Participant
      Topics: 1
      Replies: 95
      Points: 435
      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: 17
      Replies: 1951
      Points: 3,985
      Helping Hand
      Rank: Community Hero

      Here is one method:

      Timezones can be enumerated like so:

      Output:

Viewing 4 reply threads
  • The topic ‘Convert string date format to DateTime object’ is closed to new replies.