mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-01-12 22:50:20 +08:00
[android][utils] timestampToUTC method
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user