Time Zones / Time Formating

Hello all,

I have a string with a Date and time, which looks like the following:

Fri, 28 Jul 2006 15:26:40 +0200
Fri, 28 Jul 2006 15:26:40 -0200
Fri, 28 Jul 2006 15:26:40 UT

Fri, 28 Jul 2006 15:26:40 EST...

The +0200 says the time is UT+2, the -0200 says the time ie UT-2 etc..

I need a function, which will convert the time to UT time zone. The problem is that I don't know which one of them I got..:(

Can anyone help me

Thanks.





Answer this question

Time Zones / Time Formating

  • AdriaanDavel

    Use the built in function:

    Dim TheUTCTime As DateTime = Date.UtcNow

    TheUTCTime.ToShortDateString()

    TheUTCTime.ToShortTimeString()

    TheUTCTime.ToLongDateString()

    TheUTCTime.ToLongTimeString()

    TheUTCTime.ToString("mm-DD-YY")

    Dim MyTime As DateTime = Now.ToUniversalTime()



  • DavidThi808

    I didn't understand how to do it.. :(

    Can you write a code example

    Thanks..


  • benchmarkman

    Hello Ofir,

    I believe what you will need will be DateTime.ParseExact. Standardized DAteTimeFormat Strings can be found here and custom datetime format strings can be found here.

    Be sure to follow the 3 links I provided and read thorougly. 'They should provide you with what you need as ParseExact lets you pass an array of strings and DateTime.parseExact will try each one till it finds one that matches it. Hope this helps.

    String[] MyDateFormats = new String[]

    {

    "..........",

    "........",

    }

    DateTiime ParsedDate = DateTime.ParseExact(StringInput, MyDateFormats, new CultureInfo("en-us", true), DateTimeStyles.AllowWhiteSpaces);

    You may need to use one the UTC methods additionally.


  • Time Zones / Time Formating