CFLib.org – Common Function Library Project

getIsoTimeString(datetime[, convertToUTC])

Last updated August 1, 2013

author

Ben Nadel

Version: 1 | Requires: CF9 | Library: DateLib

Description:
Takes your ColdFusion date/time object and returns a string that represents the date in ISO 8601 complaint format. This separates the date/time values with a "T" and ends with the UTC-marker, "Z". Since it uses the UTC-marker, it will convert your date/time into UTC, unless you tell it not to (using the optional argument).

Return Values:
A date string as per ISO format

Example:

currentTime = now();

// Compare the HTTP time to the ISO time.
writeOutput( "HTTP Time: " & getHttpTimeString( currentTime ) );
writeOutput( "<br />" );
writeOutput( "ISO Time: " & getIsoTimeString( currentTime ) );

Parameters:

Name Description Required
datetime A date/time object Yes
convertToUTC Whether to convert to UTC before formatting (default true) No

Full UDF Source:

/**
 * Converts your date into a time string the aheres to the ISO 8601 standard (for use with some API calls).
 * v1.0 by Ben Nadel
 * 
 * @param datetime 	 A date/time object (Required)
 * @param convertToUTC 	 Whether to convert to UTC before formatting (default true) (Optional)
 * @return A date string as per ISO format 
 * @author Ben Nadel (ben@bennadel.com) 
 * @version 1.0, August 1, 2013 
 */
string function getIsoTimeString(required date datetime, boolean convertToUTC=true) {
	if (convertToUTC) {
		datetime = dateConvert("local2utc", datetime);
	}

	// When formatting the time, make sure to use "HH" so that the
	// time is formatted using 24-hour time.
	return(
		dateFormat(datetime, "yyyy-mm-dd") &
		"T" &
		timeFormat(datetime, "HH:mm:ss") &
		"Z"
	);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson