...
Dim l1 As Long = 1546127715000
Dim l2 As Long = 1572393316601
Dim NativeMe As JavaObject
NativeMe = Me
Log("wrong")
Dim s As String = NativeMe.RunMethod("convertTime", Array(l1))
Log(s)
Dim s As String = NativeMe.RunMethod("convertTime", Array(l2))
Log(s)
Log("wrong")
Dim s As String = NativeMe.RunMethod("convertTime2", Array(l1))
Log(s)
Dim s As String = NativeMe.RunMethod("convertTime2", Array(l2))
Log(s)
Log("right")
Dim s As String = NativeMe.RunMethod("convertTime3", Array(l1))
Log(s)
Dim s As String = NativeMe.RunMethod("convertTime3", Array(l2))
Log(s)
'StartMessageLoop
End Sub
#if JAVA
import java.util.Date;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.ZoneOffset;
import java.time.ZoneId;
public static String convertTime(long time){
Date date = new Date(time);
SimpleDateFormat format = new SimpleDateFormat("YYYY.MM.dd HH:mm:ss");
return format.format(date);
}
public static String convertTime2(long millisecondsSinceEpoch) {
Instant instant = Instant.ofEpochMilli ( millisecondsSinceEpoch );
ZoneId systemZone = ZoneId.systemDefault();
ZoneOffset currentOffsetForMyZone = systemZone.getRules().getOffset(instant);
ZonedDateTime zdt = ZonedDateTime.ofInstant ( instant , currentOffsetForMyZone );
DateTimeFormatter formatter = DateTimeFormatter.ofPattern ("YYYY.MM.dd HH:mm:ss" );
return formatter.format ( zdt );
}
public static String convertTime3(long millisecondsSinceEpoch) {
Instant instant = Instant.ofEpochMilli ( millisecondsSinceEpoch );
ZonedDateTime zdt = ZonedDateTime.ofInstant ( instant , ZoneOffset.UTC );
DateTimeFormatter formatter = DateTimeFormatter.ofPattern ("YYYY.MM.dd HH:mm:ss" );
return formatter.format ( zdt );
}
#End If