KeithLaw999 wrote:
> so if i change the datetime format will this code
actually change the forms
> date and time to the eqivilent sever datetime
if you need to handle different locales' date formats to
build selects,
something like this will help:
<cffunction access="private" name="buildLocale"
output="false" hint="creates
valid core java locale from java style locale ID">
<cfargument name="thisLocale" required="yes"
type="string">
<cfscript>
var locale=createObject("java","java.util.Locale");
var tLocale=locale.getDefault(); // if we fail fallback on
server default
var l=listFirst(arguments.thisLocale,"_");
var c="";
var v="";
switch (listLen(arguments.thisLocale,"_")) {
case 1:
tLocale=locale.init(l);
break;
case 2:
c=listLast(arguments.thisLocale,"_");
tLocale=locale.init(l,c);
break;
case 3:
c=listGetAt(arguments.thisLocale,2,"_");
v=listLast(arguments.thisLocale,"_");
tLocale=locale.init(l,c,v);
break;
}
return tLocale;
</cfscript>
</cffunction>
<cffunction access="private" name="getDateTimePattern"
output="No"
returntype="string" hint="returns locale date/time
pattern">
<cfargument name="thisLocale" required="yes"
type="string">
<cfargument name="thisDateFormat" required="no"
type="numeric" default="1">
<cfargument name="thisTimeFormat" required="no"
type="numeric" default="3">
<cfscript>
var locale=buildLocale(arguments.thisLocale);
var tDateFormat=javacast("int",arguments.thisDateFormat);
var tTimeFormat=javacast("int",arguments.thisTimeFormat);
var
tDateFormatter=createObject("java","java.text.DateFormat").getDateTimeInstance(tDateFormat,tTimeFormat,locale);
return tDateFormatter.toPattern();
</cfscript>
</cffunction>
<cffunction access="public" name="getDatePartOrder"
output="No"
returntype="string" hint="returns date part order
(day-month-year,
month-day-year, etc.) for this calendar/locale">
<cfargument name="thisLocale" required="yes"
type="string">
<cfset var datePartOrder="">
<!--- another special case, hong kong mixes chinese chars
--->
<cfif arguments.thisLocale EQ "zh_HK">
<cfset datePartOrder="year month day ampm time">
<cfreturn datePartOrder>
</cfif>
<!--- every place else --->
<cfset
datePartOrder=getDateTimePattern(arguments.thisLocale,3,3)>
<!--- short
date/time formats --->
<cfset datePartOrder=rereplace(datePartOrder,"a","ampm
","All")> <!--- change
ampm --->
<cfset
datePartOrder=rereplace(datePartOrder,"HH:mm|H:mm|HH.mm|hh:mm|h:mm|h.m.","time","All")>
<!--- change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"yyyy|yy","year","All")>
<!---
change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"MM|M","month","All")>
<!---
change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"dd|d","day","All")>
<!--- change
date bits --->
<cfset datePartOrder=rereplace(datePartOrder,"/|-|\.|,","
","All")> <!---
change delimiters --->
<cfset datePartOrder=rereplace(datePartOrder," ","
","All")> <!--- clean up --->
<cfreturn datePartOrder>
</cffunction>
<cfscript>
locales=listToArray("en_US,en_GB,fr_FR,fr_CA,en_CA,th_TH,ar_YE");
for (i=1; i LTE arrayLen(locales);i=i+1) {
writeoutput("#locales
#: #getDatePartOrder(locales)#<br>");
}
</cfscript>
this mess (actually part of a larger CFC that handles i18n
stuff) will return a
date part order for whatever locales you feed it (has to be
java style locale
IDs, if you're on cf7 or later you can use those in place of
the old,
long-winded cf style locales). from that you can arrange your
selects in the
correct order for your users & correctly lsParseDateTime
what they pick into a
valid cf datetime.