This entry is part of the Maximo Java Development series.
If you need to format dates and numbers into a locale-sensitive string or if you just need to convert data between different types then take a look at psdi.util.MaxType class.
For example, the following piece of code shows how to correctly format a currency amount into a string.
MaxType mt = new MaxType(MaxType.AMOUNT);
mt.setValue(10.1234);
String s = mt.asLocaleString();
Formatting and converting data in Java
Hi,
thanks for this article. It points me in the right direction, however as Java dummy I have big problem with converting a date.
I need to copy DATETIME field into DATE field. I tried setValue("DATEFIELD", getDate("DATETIMEFIELD")); but this fails with "Date format invalid" whenever locale is set to anything else than "us". How to make it work? Can you support me?
Interesting…
I have tried this code and it works:
Date d = asset.getDate("STATUSDATE");
asset.setValue("INSTALLDATE", d);
Where STATUSDATE is a DATETIME and INSTALLDATE is a DATE.
Where are you setting the locale?
Hi Bruno,
thanks for the prompt answer!
Now it works! It seems that the cast made a huge difference.
Thanks a lot!
Robert
Hi Bruno,
Also, you can use following code:
String s = psdi.util.MXFormat.amountToString(10.1234);
Kind Regards,
Max.