Get regional settings of OS using Servoy

Hi, is there a way to get the regional settings of OS using Servoy API? I am trying to display date formats depending on the regional setting.

that should go automatic, when you don’t push a format from the server to the client.
But if you want to bypass that completely you could use some java in your scripts things like:

new java.text.SimpleDateFormat().toPattern()

jcompagner:
that should go automatic, when you don’t push a format from the server to the client.
But if you want to bypass that completely you could use some java in your scripts things like:

new java.text.SimpleDateFormat().toPattern()

Excellent. Thanks!

Is it possible to retrieve other information in Regional Settings such as measurement system, decimal symbol, currency, etc. in Servoy?

only through java api like DecimalFormat:
http://download.oracle.com/javase/6/doc … ormat.html

and then for example DecimalFormatSymbols:

http://download.oracle.com/javase/6/doc … mbols.html

Thanks, Johan.

When I don’t specify a format in my field, Date field displays “dd/mm/yyyyy hh:mm am/pm”. How do I tell the Servoy to remove the time from the display without affecting display from regional setting? I don’t want to set “dd/mm/yyyy” in the field’s Format property as it will override automatic retrieval of date format from regional settings.

Thanks.

you should be able to push that through the admin page default dateformat setting.

Thanks! How about the unit of measurement, like metric or U.S., can this be retrieved somewhere in Servoy configurations as well?

That information as far as i know isn’t there in standard java, If i search i do see some custom stuff but nothing default.

I have 2 types of fields, 1 field has “date and time” and the other one has “date only”. I need to get their format using the regional settings.

For the first field to display the format in the regional settings, I leave the format property blank. It displays the date and time as "d/M/yyyy h:mm:ss tt ". This is works fine.

But the problem comes when I need to display the date only on the second field. I entered “dd/MM/yyyy” in the format property to limit the textfield display to date only, however it overrides the regional settings. I still see the date based on the form designer’s date format even if I already set “MM/dd/yyyy” in the regional settings.

Is there a way to limit field displays to either “date only” or “time only” but still basing their format on regional settings?

Not directly through designer by configuring, if you set the format then that is a hard format, don’t look at if it is date only or datetime.

What i guess you can do now is look at the java class DateFormat http://download.oracle.com/javase/6/doc … ormat.html
there you can ask for a DateFormat through the various factory methods like getDateInstance for just date without time
That will return a SimpleDateFormat instance that has the toPattern() call on int
so:

	var pattern  = Packages.java.text.DateFormat.getDateInstance(Packages.java.text.DateFormat.MEDIUM).toPattern();
	application.output(pattern);
	application.output(utils.dateFormat(new Date(),pattern));

and set that property directly on the element like: element.datefield.setFormat() or through the solutionmodel
(servoy has support for display and edit so you can concat 2 of those patterns like servoy does)

you can play with the MEDIUM, you have there also SHORT and so on.

Our free DateUtils plugin offers the following properties to make this easier:

defaultDateFormat
defaultDateTimeFormat
defaultTimeFormat

This is excellent. Thanks!

patrick:
Our free DateUtils plugin offers the following properties to make this easier:

defaultDateFormat
defaultDateTimeFormat
defaultTimeFormat

Hi Patrick!

We are getting an exception

2011-11-02 09:38:24,542 ERROR [AWT-EventQueue-0] com.servoy.j2db.util.Debug - Throwable
java.text.ParseException: stringToValue passed invalid value
	at com.servoy.j2db.util.gui.FixedMaskFormatter.stringToValue(FixedMaskFormatter.java:483)
	at com.servoy.j2db.util.gui.FixedMaskFormatter.stringToValue(FixedMaskFormatter.java:389)
	at com.servoy.j2db.smart.dataui.DataField$NullDateFormatter$FixedMaskDateFormatter.stringToValue(DataField.java:547)
	at javax.swing.JFormattedTextField.commitEdit(Unknown Source)
	at com.servoy.j2db.smart.dataui.DataField.commitEdit(DataField.java:1840)
	at com.servoy.j2db.smart.dataui.DataField$1.fireLeaveCommands(DataField.java:695)
	at com.servoy.j2db.smart.dataui.EventExecutor.focusLost(EventExecutor.java:257)
	at java.awt.AWTEventMulticaster.focusLost(Unknown Source)

During onload, we get the plugins.DateUtils.defaultDateFormat and replace the design format(dd/MM/yyyy|mask). In our case, the defaultDateFormat returned was MMM d,yyyy and thus the new format we assigned to the element is (MMM d,yyyy|mask). We were unable to enter characters in the text field. So I tried to enter digits 01012011. once I tab out of the field the exception above appeared.

Let me know your insights.

Thanks!

this:

MMM d,yyyy|mask

will never work for input, you can’t mask that.
Mask exactly that mask, so every char of the format must be used (and not more) in the typed in value.

this: MMM d,yyyy

is really a display value format, it is not really an edit format, because you have there a single ‘d’ but that doesn’t have to be single at all.