So my app fetches from information from a JSON file from a server, of which there are a few date/time values. The time and date are in UTC. I need to display these in my app, in the users local timezone.
Example of the data from JSON:
"start":"2018-10-20 03:00:00","finish":"2018-10-20 05:00:00"
My code so far, which display the date and time fine, in UTC..
val dateStringStart = radioScheduleDMList.get(position).start
val dateStringEnd = radioScheduleDMList.get(position).finish
val date = SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).parse(dateStringStart)
val dateEnd = SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).parse(dateStringEnd)
val day = SimpleDateFormat("d MMM").format(date)
val startDate = SimpleDateFormat("ha").format(date)
val endDate = SimpleDateFormat("ha").format(dateEnd)
How can I go about displaying this data using the devices timezone? I've been googling for hours.
Using the above example, my app shows "20 OCT" for the date, and "3AM-5AM" for the time. In my case, I live in Australia (GMT+10) so I would expect day "20 OCT" and "1PM-3PM". In short, I want to detect the user’s timezone offset from UTC and apply it for display.