[android][utils] timestampToUTC method

This commit is contained in:
Salakar
2018-09-25 18:58:30 +01:00
parent e0d1f64898
commit 81adcaddbe

View File

@@ -12,8 +12,13 @@ import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import javax.annotation.Nullable;
@@ -22,6 +27,14 @@ import javax.annotation.Nullable;
public class Utils {
private static final String TAG = "Utils";
public static String timestampToUTC(long timestamp) {
Calendar calendar = Calendar.getInstance();
Date date = new Date((timestamp + calendar.getTimeZone().getOffset(timestamp)) * 1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(date);
}
/**
* send a JS event
**/
@@ -156,7 +169,7 @@ public class Utils {
try {
reactContext = (ReactContext) context;
} catch(ClassCastException exception) {
} catch (ClassCastException exception) {
// Not react context so default to true
return true;
}