I am building a API Java code that is downloading into a CSV file a list of transactions, disputes and payments made through Paypal for this company I work for. One of the columns from the CSV file is a date related column as you can see below:
transactionData.add(String.valueOf(transaction.getDisputes().get(i).getReceivedDate()));
The issue is that all values for the data column above is coming in the CSV as a XMLGregorianDate:
java.util.GregorianCalendar[time=1589760000000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=”UTC”,offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2020,MONTH=4,WEEK_OF_YEAR=21,WEEK_OF_MONTH=3,DAY_OF_MONTH=18,DAY_OF_YEAR=139,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]
What changes should I make to the line above to give me the data in timestamp with timezone i.e. “yyyy-mm-dd hh:mi:ss+/-tz”?
2
Answers
GregorianCalendar
extendsCalendar
that has agetTime():Date
method : https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getTime()You have two options to specify the date-time output format:
1- Using Java 8 Date and Time API classes under the java.time package (recommended)
2- Using the legacy Date-Time classes such as java.util.Date & java.text.SimpleDateFormat.