The problem with the LSParseDateTime function on the server, despite the correct installation of the server locale

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

I in Europe use the date format in euros, so September 10, 1957 - September 10, 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> 

Test computer output

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

The same code output on a live server

 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 - Windows Web Server 2008 R2. I checked the control panel> date and time and it is correctly installed in London. The web server is IIS7, but I don’t think it would affect anything?

IN region and Language, the location is set to United Kingdom and to Administrative (change the locale system), this is also true since English (United Kingdom)

Update: as far as CF is concerned, he believes that the server is in the US locale.

Launching 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> LSparsedatetime output = #lsparsedatetime(testDate)#<br> parsedatetime output = #parsedatetime(testDate)#<br> </cfoutput> 

Gives this way out

 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 is the confirmation of the server settings.

alt textalt text

Forced localization with setLocale in code eliminates the correct behavior.

+4
source share
2 answers

Another option is to force the locale to use SetLocale , consider this example:

 <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 am in Ukraine, so the conclusion is 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 necessary job.

+4
source

I want this to be related to the locale , not your time zone.

Your locale on your real server seems to be installed in the USA, since it sees 10/09/1957 as October 9, while your test server sees it in the British style, i.e. 10 September.

You need to compare the local settings on the servers.

Try region and language β†’ Administrative (tab) β†’ Change system language and compare.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1335724/


All Articles