Translating to local time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Shaw

    #1

    Translating to local time

    Some examples in datetime format:
    Thu, 25 Jan 2007 10:22:39 -0500
    Thu, 25 Jan 2007 09:12:17 -0800
    Thu, 25 Jan 2007 10:26:04 -0800
    Thu, 25 Jan 2007 10:27:26 -0800
    Thu, 25 Jan 2007 19:28:28 +0000

    What's the easiest way to get these into my local timezone (AST-Atlantic
    Standard Time)?

    Change them to GMT, then do -0400?


  • Kevin Spencer

    #2
    Re: Translating to local time

    The first thing you need to do is to determine what Time Zone they
    originated from.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Software Composer
    Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


    The shortest distance between 2 points is a curve.

    "Marco Shaw" <marcoDOTshaw_@ _gmailDOTcomwro te in message
    news:%23baI76LQ HHA.1276@TK2MSF TNGP04.phx.gbl. ..
    Some examples in datetime format:
    Thu, 25 Jan 2007 10:22:39 -0500
    Thu, 25 Jan 2007 09:12:17 -0800
    Thu, 25 Jan 2007 10:26:04 -0800
    Thu, 25 Jan 2007 10:27:26 -0800
    Thu, 25 Jan 2007 19:28:28 +0000
    >
    What's the easiest way to get these into my local timezone (AST-Atlantic
    Standard Time)?
    >
    Change them to GMT, then do -0400?
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Translating to local time

      Kevin Spencer <unclechutney@n othinks.comwrot e:
      The first thing you need to do is to determine what Time Zone they
      originated from.
      That's what the -0500, -0800, -0800 etc are for. All relative to UTC.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Translating to local time

        Marco Shaw <marcoDOTshaw_@ _gmailDOTcomwro te:
        Some examples in datetime format:
        Thu, 25 Jan 2007 10:22:39 -0500
        Thu, 25 Jan 2007 09:12:17 -0800
        Thu, 25 Jan 2007 10:26:04 -0800
        Thu, 25 Jan 2007 10:27:26 -0800
        Thu, 25 Jan 2007 19:28:28 +0000
        >
        What's the easiest way to get these into my local timezone (AST-Atlantic
        Standard Time)?
        >
        Change them to GMT, then do -0400?
        Try this: (works on my box, but I'm in GMT!)

        using System;
        using System.Globaliz ation;

        class Program
        {
        static void Main(string[] args)
        {
        string[] data = new string[]
        {"Thu, 25 Jan 2007 10:22:39 -0500",
        "Thu, 25 Jan 2007 09:12:17 -0800",
        "Thu, 25 Jan 2007 10:26:04 -0800",
        "Thu, 25 Jan 2007 10:27:26 -0800",
        "Thu, 25 Jan 2007 19:28:28 +0000"};

        foreach (string x in data)
        {
        Parse(x);
        }
        }

        static void Parse (string x)
        {
        DateTime dt = DateTime.ParseE xact
        (x, "ddd, dd MMM yyyy HH:mm:ss zzz",
        CultureInfo.Inv ariantCulture,
        DateTimeStyles. AdjustToUnivers al);

        dt = dt.ToLocalTime( );
        Console.WriteLi ne (dt);
        }
        }


        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        • Kevin Spencer

          #5
          Re: Translating to local time

          I thought so, but I was unfamiliar with the DateTime format syntax being
          used, so I was not going to assume that this was the case. After doing some
          research, I have found this format as part of RFC 822 (ARPA Internet Text
          Message).

          --
          HTH,

          Kevin Spencer
          Microsoft MVP
          Software Composer
          Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


          The shortest distance between 2 points is a curve.

          "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
          news:MPG.20251a c4d1b13d2598d7f a@msnews.micros oft.com...
          Kevin Spencer <unclechutney@n othinks.comwrot e:
          >The first thing you need to do is to determine what Time Zone they
          >originated from.
          >
          That's what the -0500, -0800, -0800 etc are for. All relative to UTC.
          >
          --
          Jon Skeet - <skeet@pobox.co m>
          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          If replying to the group, please do not mail me too

          Comment

          Working...