Formatting and converting data in Java

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
Share this post...

4 thoughts on “Formatting and converting data in Java

  1. 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?

  2. 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?

  3. Hi Bruno,

    thanks for the prompt answer!
    Now it works! It seems that the cast made a huge difference.
    Thanks a lot!

    Robert

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top