Android Long to Date Convert getLocalTimeFromUTCMillis(long utcMillis)

Here you can find the source of getLocalTimeFromUTCMillis(long utcMillis)

Description

Convert a UTC timestamp into device local time

Parameter

Parameter Description
utcMillis a parameter

Declaration

static long getLocalTimeFromUTCMillis(long utcMillis) 

Method Source Code

//package com.java2s;
import java.util.Calendar;

public class Main {
    /**/*from  ww  w  .  j  av  a 2s  .  c  o  m*/
     * Convert a UTC timestamp into device local time
     * 
     * @param utcMillis
     * @return
     */
    static long getLocalTimeFromUTCMillis(long utcMillis) {
        return utcMillis - getTimeZoneOffsetInMillis();
    }

    /**
     * @return the timezone offset of the current device relative to UTC
     */
    static long getTimeZoneOffsetInMillis() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    }
}

Related

  1. getFormattedTime(String dateTimeFormat, long timestamp)
  2. getFriendlyDate(Context context, long timestamp)
  3. getHour(long dateTimeMillis)
  4. getHour(long timeMillis)
  5. getHoursAndMinutes(long dateTimeMillis)
  6. getLongOfString(String date)
  7. getMinute(long dateTimeMillis)
  8. getMinutesSinceStartOfDay(long milliseconds)
  9. getMonth(long dateTimeMillis)