Skip to content

change offset without changing local time

I have a date that is in IST format. Which is something like the


I have the following code for the above output

    val fromtTime = Date()
    val startOfDay = fromtTime.startOfDay()

    val dateFormat = SimpleDateFormat(

    val startOfDate = dateFormat.format(startOfDay)

startOfDay is just and extenstion function which is something like this

fun Date.startOfDay(): Date {
    val now = Calendar.getInstance()
    now.time = this
    now.set(Calendar.HOUR_OF_DAY, 0)
    now.set(Calendar.MINUTE, 0)
    now.set(Calendar.SECOND, 0)
    return now.time

But, what the backend really wants is in the below format with -8:00.


Is there any way I can format it to have -08:00 in the end of the string whenever I select the timezone as “America/Los_Angeles”, because “America/Los_Angeles” is supposed to have the timezone which is -8 hours from the GMT.




I recommend that you use java.time, the modern Java date and time API, for your date and time work. Please excuse my Java syntax.

    String forBackend =

I ran this code in Asia/Kolkata time zone just now (within the first hour after midnight on 2021-12-08). The output was:


A LocalDate is a date without time of day or time zone, so just gives us the current day in India (when Asia/Kolkata is our default time zone) without time of day. Then the call to atStartOfDay() gives us the start if the same date in America/Los_Angeles time zone. Finally the format you asked for is built in, so we are using the predefined formatter and not writing our own format pattern string.

When summer time (DST) begins in North America, the offset will be -07:00 instead.

5 People found this is helpful