Question

I have users in China who use the Chinese (Simplified) regional setting. When they enter a date they do so in the usual Chinese style (yyyy/mm/dd), but my Java agent reads it as yyyy/dd/mm.

For example, "2013/12/15" (15 December 2013) will be interpreted as the 12th day of the 15th month of 2013, hence 12 March 2014.

I am using

Item itm = dataDoc.getFirstItem("CAPublicationDate"); 
DateTime dt = itm.getDateTimeValue();
String adate = dt.getDateOnly();
int yyyy = Integer.parseInt(adate.substring(6));
int mm = Integer.parseInt(adate.substring(3,5));
int day = Integer.parseInt(adate.substring(0,2)); 
Calendar pubdate  =  Calendar.getInstance();                
pubdate.set(yyyy, mm-1, day);

The relevant field is a Time/Date field and in the Notes document properties on a Chinese machine the date shows correctly as "2013/12/15", and on my UK machine it shows correctly as "15/12/2013". It's only in the java agent that it is misinterpreted.

Any suggestions?

Was it helpful?

Solution

Use .toJavaDate() to return a java.util.Date object and then work with that.

Example:

Item itm = dataDoc.getFirstItem("CAPublicationDate"); 
DateTime dt = itm.getDateTimeValue();
Date javaDate = dt.toJavaDate();
Calendar pubdate  =  Calendar.getInstance();
pubdate.setTime(javaDate);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top