getTimeZone(dateTimeIn)
Last updated January 06, 2004
Version: 1 | Requires: CF5 | Library: DateLib
Description:
Returns the Time Zone Code (string) that corresponds to the dateTime passed in. Will return 'UNK' if the dateTime passed in does not match the set of time zones.
Return Values:
Returns a string.
Example:
<cfoutput>#getTimeZone(now())#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
dateTimeIn | The date to parse. | Yes |
Full UDF Source:
/**
* Returns the Time Zone Code (string) that corresponds to the dateTime passed in.
*
* @param dateTimeIn The date to parse. (Required)
* @return Returns a string.
* @author Tony Felice (staff@nokama.com)
* @version 1, January 6, 2004
*/
function getTimeZone(dateTimeIn) {
var timeZoneInfo = GetTimeZoneInfo();
var dateGMT = mid(replace(getHttpTimeString(),"GMT","","ALL"),6,len(replace(getHttpTimeString(),"GMT","","ALL")));
var dateFactor = dateCompare(dateTimeIn, dateGMT);
var dateDelta = round(DateDiff("n", dateTimeIn, dateGMT)/60);
var trueZoneOffset = (dateDelta * dateFactor);
var offsetList="";
var zoneCodeList="";
var listPos="";
var timeZoneCode="";
//standard time zones
var stdZoneCodeList = "HST,AKST,PST,MST,CST,EST,AST,NST,GMT,CET,EET,MSK,AWST,ACST,AEST";
var stdOffsetList = "-10,-9,-8,-7,-6,-5,-4,-3.5,0,1,2,3,8,9.5,10";
// daylight saving time zones
var dstZoneCodeList = "AKDT,PDT,MDT,CDT,EDT,ADT,NDT,GMT,WEST,CEST,EEST,MSD,ACDT,AEDT";
var dstOffsetList = "-8,-7,-6,-5,-4,-3,-2.5,0,1,2,3,4,10.5,11";
if(timeZoneInfo.isDSTOn IS "YES"){
offsetList = dstOffsetList;
zoneCodeList = dstZoneCodeList;
} else {
offsetList = stdOffsetList;
zoneCodeList = stdZoneCodeList;
}
listPos = ListFindNoCase(OffsetList,trueZoneOffset);
if(listPos NEQ 0) timeZoneCode = ListGetAt(ZoneCodeList,listPos);
else timeZoneCode = "UNK";
return timeZoneCode;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016