Converts the timestamp from iOS system to the Date object - Android java.util

Android examples for java.util:Date Compare

Description

Converts the timestamp from iOS system to the Date object

Demo Code

import android.util.Log;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main{
    /** The reference date of the iOS system. */
    public static final long NS_DATE_REFERENCE_SEC = 978307200;
    /**/* w  w w .jav a 2  s.c  om*/
     * Converts the timestamp from iOS system to the Date object in Java
     * 
     * @param timestamp
     *            the timestamp from iOS
     * @return a Date object represents the given timestamp from iOS System
     */
    public static Date getDateFromNSTimestamp(long timestamp) {
        long time = (NS_DATE_REFERENCE_SEC + timestamp) * 1000;
        return new Date(time);
    }

}

Related Tutorials