Converts local time to Universal Coordinated Time (UTC) or UTC to local time, based on parameters. The function uses the daylight savings settings in the executing computer to compute daylight savings time, if required.
DateConvert(conversion-type, date)
GetTimeZoneInfo,
CreateDateTime,
DatePart
Parameter |
Description |
---|---|
conversion-type |
|
date |
ColdFusion date and time string. To create a ColdFusion date and time, use CreateDateTime. |
When passing a date/time value as a string, enclose it in quotes. Otherwise, it is interpreted as a number representation of a date/time object.
Note You can pass the CreateDate function or Now function as the date parameter of |
<!--- This example shows the use of DateConvert ---> <html> <head> <title>DateConvert Example</title> </head> <basefont face = "Arial, Helvetica" size = 2> <body bgcolor = "#FFFFD5"> <H3>DateConvert Example</H3> <!--- This part of the example shows the conversion of the current date and time to UTC time and back again. ---> <cfset curDate = Now()> <P><cfoutput>The current date and time: #curDate#. </cfoutput></P> <cfset utcDate = DateConvert("local2utc", curDate)> <cfoutput> <P>The current date and time converted to UTC time: #utcDate#.</P> </cfoutput> <!--- This code checks whether the form was submitted. If it was submitted the code generates the CFML date with the CreateDateTime function. ---> <cfif IsDefined("FORM.submit")> <cfset yourDate = CreateDateTime(FORM.year, FORM.month, FORM.day, FORM.hour,FORM.minute, FORM.second)> <P><cfoutput>Your date value, presented as a ColdFusion date/time string:#yourdate#.</cfoutput></P> <cfset yourUTC = DateConvert("local2utc", yourDate)> <P><cfoutput>Your date and time value, converted into Universal Coordinated Time (UTC): #yourUTC#.</cfoutput></P> <P><cfoutput>Your UTC date and time, converted back to local date and time: #DateConvert("utc2local", yourUTC)#. </cfoutput></P> <cfelse> Type the date and time, and press Enter to see the conversion. </cfif> <Hr size = "2" color = "#0000A0"> <form action = "dateconvert.cfm" method = "POST"> <P>Please enter the year, month and day in integer format for the date value to view: <table cellspacing = "2" cellpadding = "2" border = "0"> <tr> <td>Year</td> <td><input type = "Text" name = "year" value = "1998" validate = "integer" required = "Yes"></td> </tr> <tr> <td>Month</td> <td><input type = "Text" name = "month" value = "6" RANGE = "1,12" message = "Please enter a month (1-12)" validate = "integer" required = "Yes"></td> </tr> <tr> <td>Day</td> <td><input type = "Text" name = "day" value = "8" RANGE = "1,31" message = "Please enter a day of the month (1-31)" validate = "integer" required = "Yes"></td> </tr> <tr> <td>Hour</td> <td><input type = "Text" name = "hour" value = "16" RANGE = "0,23" message = "You must enter an hour (0-23)" validate = "integer" required = "Yes"></td> </tr> <tr> <td>Minute</td> <td><input type = "Text" name = "minute" value = "12" RANGE = "0,59" message = "You must enter a minute value (0-59)" validate = "integer" required = "Yes"></td> </tr> <tr> <td>Second</td> <td><input type = "Text" name = "second" value = "0" RANGE = "0,59" message = "You must enter a value for seconds (0-59)" validate = "integer" required = "Yes"></td> </tr> <tr> <td><input type = "Submit" name = "submit" value = "Submit"></td> <td><input type = "RESET"></td> </tr> </table> </body> </html>