Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date translation
Message
 
 
À
21/08/2004 12:28:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00935198
Message ID:
00935281
Vues:
22
This message has been marked as the solution to the initial question of the thread.
>>I have this format that I need to translate into a DateTime format:
>>
>>
Thu, 20 May 2004 08:50:03 PDT
>>
>>Is there a simple way to have that into my own time zone properly formatted?
>
>Michel -
>are the spaces always there between each date element?
>if so -
>you should be able to parse it with at() and substr()
>do you care about the name of the day? if not, you can skip that.
>after 'getting it all' you will still need to add time for your zone.
>
>i feel [ug] it could be done in 20 lines or less.
>
>regards [Bill]

Here is what happens when I get bored:
#Define CR CHR(13)

cTimeZones = "A" + CR + "Alpha Time Zone" + CR + "Military" + CR + "+1" + CR + "0" + CR ;
	+ "ACDT" + CR + "Australian Central Daylight Time" + CR + "Australia" + CR + "+10" + CR + "30" + CR ;
	+ "ACST" + CR + "Australian Central Standard Time" + CR + "Australia" + CR + "+9" + CR + "30" + CR ;
	+ "ADT" + CR + "Atlantic Daylight Time" + CR + "North America" + CR + "-3" + CR + "0" + CR ;
	+ "AEDT" + CR + "Australian Eastern Daylight Time" + CR + "Australia" + CR + "+11" + CR + "0" + CR ;
	+ "AEST" + CR + "Australian Eastern Standard Time" + CR + "Australia" + CR + "+10" + CR + "0" + CR ;
	+ "AKDT" + CR + "Alaska Daylight Time" + CR + "North America" + CR + "-8" + CR + "0" + CR ;
	+ "AKST" + CR + "Alaska Standard Time" + CR + "North America" + CR + "-9" + CR + "0" + CR ;
	+ "AST" + CR + "Atlantic Standard Time" + CR + "North America" + CR + "-4" + CR + "0" + CR ;
	+ "AWST" + CR + "Australian Western Standard Time" + CR + "Australia" + CR + "+8" + CR + "0" + CR ;
	+ "B" + CR + "Bravo Time Zone" + CR + "Military" + CR + "+2" + CR + "0" + CR ;
	+ "BST" + CR + "British Summer Time" + CR + "Europe" + CR + "+1" + CR + "0" + CR ;
	+ "C" + CR + "Charlie Time Zone" + CR + "Military" + CR + "+3" + CR + "0" + CR ;
	+ "CDT" + CR + "Central Daylight Time" + CR + "Australia" + CR + "+10" + CR + "30" + CR ; 
	+ "CDT" + CR + "Central Daylight Time" + CR + "North America" + CR + "-5" + CR + "0" + CR ;
	+ "CEST" + CR + "Central European Summer Time" + CR + "Europe" + CR + "+2" + CR + "0" + CR ;
	+ "CET" + CR + "Central European Time" + CR + "Europe" + CR + "+1" + CR + "0" + CR ;
	+ "CST" + CR + "Central Standard Time" + CR + "Australia" + CR + "+9" + CR + "30" + CR ;
	+ "CST" + CR + "Central Standard Time" + CR + "North America" + CR + "-6" + CR + "0" + CR ;
	+ "CXT" + CR + "Christmas Island Time" + CR + "Australia" + CR + "+7" + CR + "0" + CR ;
	+ "D" + CR + "Delta Time Zone" + CR + "Military" + CR + "+4" + CR + "0" + CR ;
	+ "E" + CR + "Echo Time Zone" + CR + "Military" + CR + "+5" + CR + "0" + CR ;
	+ "EDT" + CR + "Eastern Daylight Time" + CR + "Australia" + CR + "+11" + CR + "0" + CR ;
	+ "EDT" + CR + "Eastern Daylight Time" + CR + "North America" + CR + "-4" + CR + "0" + CR ;
	+ "EEST" + CR + "Eastern European Summer Time" + CR + "Europe" + CR + "+3" + CR + "0" + CR ;
	+ "EET" + CR + "Eastern European Time" + CR + "Europe" + CR + "+2" + CR + "0" + CR ;
	+ "EST" + CR + "Eastern Standard Time" + CR + "Australia" + CR + "+10" + CR + "0" + CR ;
	+ "EST" + CR + "Eastern Standard Time" + CR + "North America" + CR + "-5" + CR + "0" + CR ;
	+ "F" + CR + "Foxtrot Time Zone" + CR + "Military" + CR + "+6" + CR + "0" + CR ;
	+ "G" + CR + "Golf Time Zone" + CR + "Military" + CR + "+7" + CR + "0" + CR

cTimeZones = cTimeZones ;
	+ "GMT" + CR + "Greenwich Mean Time" + CR + "Europe" + CR + "0" + CR + "0" + CR ;
	+ "H" + CR + "Hotel Time Zone" + CR + "Military" + CR + "+8" + CR + "0" + CR ;
	+ "HAA" + CR + "Heure Avancée de l'Atlantique" + CR + "North America" + CR + "-3" + CR + "0" + CR ;
	+ "HAC" + CR + "Heure Avancée du Centre" + CR + "North America" + CR + "-5" + CR + "0" + CR ;
	+ "HADT" + CR + "Hawaii-Aleutian Daylight Time" + CR + "North America" + CR + "-9" + CR + "0" + CR ;
	+ "HAE" + CR + "Heure Avancée de l'Est" + CR + "North America" + CR + "-4" + CR + "0" + CR ;
	+ "HAP" + CR + "Heure Avancée du Pacifique" + CR + "North America" + CR + "-7" + CR + "0" + CR ;
	+ "HAR" + CR + "Heure Avancée des Rocheuses" + CR + "North America" + CR + "-6" + CR + "0" + CR ;
	+ "HAST" + CR + "Hawaii-Aleutian Standard Time" + CR + "North America" + CR + "-10" + CR + "0" + CR ;
	+ "HAT" + CR + "Heure Avancée de Terre-Neuve" + CR + "North America" + CR + "-2" + CR + "-30" + CR ;
	+ "HAY" + CR + "Heure Avancée du Yukon North" + CR + "America" + CR + "-8" + CR + "0" + CR ;
	+ "HNA" + CR + "Heure Normale de l'Atlantique" + CR + "North America" + CR + "-4" + CR + "0" + CR ;
	+ "HNC" + CR + "Heure Normale du Centre" + CR + "North America" + CR + "-6" + CR + "0" + CR ;
	+ "HNE" + CR + "Heure Normale de l'Est" + CR + "North America" + CR + "-5" + CR + "0" + CR ;
	+ "HNP" + CR + "Heure Normale du Pacifique" + CR + "North America" + CR + "-8" + CR + "0" + CR ;
	+ "HNR" + CR + "Heure Normale des Rocheuses" + CR + "North America" + CR + "-7" + CR + "0" + CR ;
	+ "HNT" + CR + "Heure Normale de Terre-Neuve" + CR + "North America" + CR + "-3" + CR + "-30" + CR ;
	+ "HNY" + CR + "Heure Normale du Yukon" + CR + "North America" + CR + "-9" + CR + "0" + CR ;
	+ "I" + CR + "India Time Zone" + CR + "Military" + CR + "+9" + CR + "0" + CR ;
	+ "IST" + CR + "Irish Summer Time" + CR + "Europe" + CR + "+1" + CR + "0" + CR ;
	+ "K" + CR + "Kilo Time Zone" + CR + "Military" + CR + "+10" + CR + "0" + CR ;
	+ "L" + CR + "Lima Time Zone" + CR + "Military" + CR + "+11" + CR + "0" + CR ;
	+ "M" + CR + "Mike Time Zone " + CR + "Military" + CR + "+12" + CR + "0" + CR ;
	+ "MDT" + CR + "Mountain Daylight Time" + CR + "North America" + CR + "-6" + CR + "0" + CR ;
	+ "MESZ" + CR + "Mitteleuropäische Sommerzeit" + CR + "Europe" + CR + "+2" + CR + "0" + CR ;
	+ "MEZ" + CR + "Mitteleuropäische Zeit" + CR + "Europe" + CR + "+1" + CR + "0" + CR ;
	+ "MST" + CR + "Mountain Standard Time" + CR + "North America" + CR + "-7" + CR + "0" + CR ;
	+ "N" + CR + "November Time Zone" + CR + "Military" + CR + "-1" + CR + "0" + CR ;
	+ "NDT" + CR + "Newfoundland Daylight Time" + CR + "North America" + CR + "-2" + CR + "-30" + CR ;
	+ "NFT" + CR + "Norfolk (Island) Time" + CR + "Australia" + CR + "+11" + CR + "30" + CR ;
	+ "NST" + CR + "Newfoundland Standard Time" + CR + "North America" + CR + "-3" + CR + "-30" + CR ;
	+ "O" + CR + "Oscar Time Zone" + CR + "Military" + CR + "-2" + CR + "0" + CR ;
	+ "P" + CR + "Papa Time Zone" + CR + "Military" + CR + "-3" + CR + "0" + CR ;
	+ "PDT" + CR + "Pacific Daylight Time" + CR + "North America" + CR + "-7" + CR + "0" + CR ;
	+ "PST" + CR + "Pacific Standard Time" + CR + "North America" + CR + "-8" + CR + "0" + CR ;
	+ "Q" + CR + "Quebec Time Zone" + CR + "Military" + CR + "-4" + CR + "0" + CR ;
	+ "R" + CR + "Romeo Time Zone" + CR + "Military" + CR + "-5" + CR + "0" + CR ;
	+ "S" + CR + "Sierra Time Zone" + CR + "Military" + CR + "-6" + CR + "0" + CR ;
	+ "T" + CR + "Tango Time Zone" + CR + "Military" + CR + "-7" + CR + "0" + CR ;
	+ "U" + CR + "Uniform Time Zone" + CR + "Military" + CR + "-8" + CR + "0" + CR ;
	+ "UTC" + CR + "Coordinated Universal Time" + CR + "Europe" + CR + "0" + CR + "0" + CR ;
	+ "V" + CR + "Victor Time Zone" + CR + "Military" + CR + "-9" + CR + "0" + CR ;
	+ "W" + CR + "Whiskey Time Zone" + CR + "Military" + CR + "-10" + CR + "0" + CR ;
	+ "WEST" + CR + "Western European Summer Time" + CR + "Europe" + CR + "+1" + CR + "0" + CR ;
	+ "WET" + CR + "Western European Time" + CR + "Europe" + CR + "0" + CR + "0" + CR ;
	+ "WST" + CR + "Western Standard Time" + CR + "Australia" + CR + "+8" + CR + "0" + CR ;
	+ "X" + CR + "-ray Time Zone" + CR + "Military" + CR + "-11" + CR + "0" + CR ;
	+ "Y" + CR + "Yankee Time Zone" + CR + "Military" + CR + "-12" + CR + "0" + CR ;
	+ "Z" + CR + "Zulu Time Zone" + CR + "Military" + CR + "0" + CR + "0" + CR

iTotalLines = ALINES( aTimeZones, cTimeZones )

#IF .F. THEN
	FOR iRow = 0 TO (iTotalLines / 5) - 1
		? PADL( iRow + 1, 3 )
		?? " "
		FOR iCol = 1 TO 5
			iElement = (iRow * 5) + iCol
			?? aTimeZones[ iElement ] + ", "
		NEXT iCol
	NEXT iRow
#ENDIF

cDateToConvert = "Thu, 20 May 2004 08:50:03 PDT"

iAbbreviation = ASCAN( aTimeZones, SUBSTR( cDateToConvert, RAT( " ", cDateToConvert ) + 1))
iToUTCHours = VAL(aTimeZones[ iAbbreviation + 3 ]) * -1
iToUTCMinutes = VAL(aTimeZones[ iAbbreviation + 4 ]) * -1

tConverted = DATETIME( VAL( SUBSTR( cDateToConvert, AT( " ", cDateToConvert, 3 ) + 1 )) ;
		, (AT( SUBSTR( cDateToConvert, 9, AT( " ", cDateToConvert, 3) -9 ) ;
			, "January  " ;
			+ "February " ;
			+ "March    " ;
			+ "April    " ;
			+ "May      " ;
			+ "June     " ;
			+ "July     " ;
			+ "August   " ;
			+ "September" ;
			+ "October  " ;
			+ "November " ;
			+ "December " ) +8 ) / 9 ;
		, VAL( SUBSTR( cDateToConvert, 6)) ;
		, VAL( SUBSTR( cDateToConvert, AT( " ", cDateToConvert, 4 ) + 1 )) ;
		, VAL( SUBSTR( cDateToConvert, AT( " ", cDateToConvert, 4 ) + 4 )) ;
		, VAL( SUBSTR( cDateToConvert, AT( " ", cDateToConvert, 4 ) + 7 )))

? PADL("Source : ",17), cDateToConvert

*- UTC converion applied to converted DateTime as seconds, just in case
*- the change results in a date change. Applying the change above, might
*- result in invalid hours and minutes (i.e. negative values or values
*- greater than 23 (for hours) or 59 (for minutes).

tUTC = tConverted + (60*60*iToUTCHours) + (60*iToUTCMinutes)
? PADL("UTC : ",17), tUTC

tLocal = tUTC - (60*60*4)
? "Local (Quebec) : ", tLocal
censored.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform