I am trying to get the current date and time in ISO 8601 format. My code below returns the date 14 days later and incorrect time. I need the correct format and current date for an api request.
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply {
this.timeZone = TimeZone.getTimeZone("CST")
}
val now = Calendar.getInstance(TimeZone.getTimeZone("CST"))
val sendDateUAT = formatter.format(now.time)
Log.d(TAG, "sendDate: $sendDateUAT")
This returns: 2019-08-05T02:53:40Z
EDIT: This is now.time:
java.util.GregorianCalendar[time=1564973620006,areFieldsSet=true,lenient=true,zone=GMT,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2019,MONTH=7,WEEK_OF_YEAR=32,WEEK_OF_MONTH=2,DAY_OF_MONTH=5,DAY_OF_YEAR=217,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=2,HOUR_OF_DAY=2,MINUTE=53,SECOND=40,MILLISECOND=6,ZONE_OFFSET=0,DST_OFFSET=0]