– Common Function Library Project

zDateFormat(offset, date)

Last updated August 23, 2005


Jeffrey Pratt

Version: 1 | Requires: CF6 | Library: DateLib

It takes a GMT offset and a date object, and returns a string representation of the date as a Zulu date (yyyy-mm-ddTHH:mm:ssZ). It checks for valid offsets and dates. It's useful in formatting dates as Zulu dates for Atom feeds, etc.

Return Values:
Returns a string.


<cfset mydate = now()>
#DateFormat(myDate, "ddd, dd mmm yyyy")# #TimeFormat(myDate, "HH:mm:ss")#<br/>
#zDateFormat("-0330", myDate)#


Name Description Required
offset Offset from GMT. Yes
date The date to format. Yes

Full UDF Source:

 Formats the given date as a Zulu date.
 @param offset      Offset from GMT. (Required)
 @param date      The date to format. (Required)
 @return Returns a string. 
 @author Jeffrey Pratt ( 
 @version 1, August 23, 2005 
<cffunction name="zDateFormat" returntype="string">
    <cfargument name="offset" type="string" required="true"/>
    <cfargument name="date" type="date" required="true"/>
    <cfset var sign = Left(offset, 1)/>
    <cfset var hours = Mid(offset, 2, 2)/>
    <cfset var minutes = Mid(offset, 4, 2)/>
    <cfset var zDate = "">
    <cfset var formattedDate = "">
    <cfif not IsNumeric(offset) or len(offset) neq 5 or (sign is not "-" and sign is not "+")>
        <cfthrow type="InvalidGMTOffsetFormatException" message="A valid GMT offset is of the form '-hhmm' or '+hhmm', with 'hh' being the number of hours and 'mm' being the number of minutes by which the date is offset from GMT."/>
    <cfif sign Is "+">
        <cfset hours = -hours/>
        <cfset minutes = -minutes/>
    <cfset zDate = dateAdd("n", minutes, dateAdd("h", hours, date))/>
    <cfset formattedDate = dateFormat(zDate, "yyyy-mm-dd") & "T" & timeFormat(zDate, "HH:mm:ss") & "Z"/>
    <cfreturn formattedDate/>


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson