开发者

Problem with LSParseDateTime function on server only despite server locale correctly set

When I run this test code on my development machine it works as expected. CF9.01

I am in europe using euro date format so 10/09/1957 is 10th Sept 1957.

<cfset testDate="10/09/1957">
<cfoutput>
Initial string = "#testDate#"<br>
LSparsedatetime output = #lsparsedatetime(session.form.patientDOB)#<br>
parsedatetime output = #parsedatetime(session.form.patientDOB)#
</cfoutput>

Output on test machine is

Initial string = "10/09/1957"
LSparsedatetime output = {ts '1957-09-10 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}

Same code , output on live server is

Initial string = "10/09/1957"
LSparsedatetime output = {ts '1957-10-09 00:00:00'} 
parsedatetime output = {ts '1957-10-09 00:00:00'}

Server OS is Windows Web Server 2008 R2. I checked Control panel > date and time setting and it is correctly set to London. Web server is IIS7 but I don't think that would affect anything?

IN region and Language, location is set to United Kingdom and in Administrative (change system locale ) it is also correct as English (United Kingdom)

Update : as far as CF is concerned it thinks the server is on US locale.

Running this ...

<cfset testDate="10/09/1957">
<cfoutput>
Initial string = "#testDate#"<br>
#getLocale()#:<br>
LSparsedatetime output = #lsparsedatetime(testDate)#<br>
parsedatetime output = #parsedatetime(testDate)#<br>
<P>
<cfset SetLocale("en_GB") />
en_GB:<br>
LSpars开发者_如何学Pythonedatetime output = #lsparsedatetime(testDate)#<br>
parsedatetime output = #parsedatetime(testDate)#<br>
</cfoutput>

Gives this output

Initial string = "10/09/1957"
English (US):
LSparsedatetime output = {ts '1957-10-09 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}
en_GB:
LSparsedatetime output = {ts '1957-09-10 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}

But here's confirmation of the server settings.

Problem with LSParseDateTime function on server only despite server locale correctly set

Problem with LSParseDateTime function on server only despite server locale correctly set

Forcing locale with setLocale in the code resolves to correct behaviour.


Another option is to force the locale using SetLocale, consider this sample:

<cfset testDate="10/09/1957">
<cfoutput>
Initial string = "#testDate#"<br>
#getLocale()#:<br>
LSparsedatetime output = #lsparsedatetime(testDate)#<br>
parsedatetime output = #parsedatetime(testDate)#<br>
<cfset SetLocale("en_US") />
en_US:<br>
LSparsedatetime output = #lsparsedatetime(testDate)#<br>
parsedatetime output = #parsedatetime(testDate)#<br>
<cfset SetLocale("en_GB") />
en_GB:<br>
LSparsedatetime output = #lsparsedatetime(testDate)#<br>
parsedatetime output = #parsedatetime(testDate)#<br>
</cfoutput>

I'm in Ukraine, so the output looks as follows:

Initial string = "10/09/1957"
uk_UA:
LSparsedatetime output = {ts '1957-09-10 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}
en_US:
LSparsedatetime output = {ts '1957-10-09 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}
en_GB:
LSparsedatetime output = {ts '1957-09-10 00:00:00'}
parsedatetime output = {ts '1957-10-09 00:00:00'}

Obviously, ParseDateTime works the same with any locale, but LSParseDateTime does the needed job.


I thinnk this is to do with your locale, not your timezone.

Your locale on your live server appears to be set to US as it is seeing 10/09/1957 as the 9th of October whereas your test server sees it UK style, i.e. the 10th of September.

You'll need to compare the local setting on the servers.

Try Region & Language -> Administrative (Tab) -> Change System Locale and compare.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜