DateTime.TimeFormat = "HH:mm:ss"
DateTime.DateFormat = "YYYY.MM.dd "
Dim mm As Map
mm.Initialize
Dim l As Long = 1546127715000
mm.Put("1", l)
l = 1572393316601
mm.Put("2", l)
File.WriteMap(File.DirApp, "Dates", mm)
mm = File.ReadMap(File.DirApp, "Dates")
Log ($"Ticks ${mm.Get("1")} ==> $DateTime{mm.Get("1")}"$)
Log ($"Ticks ${mm.Get("2")} ==> $DateTime{mm.Get("2")}"$)
...
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
wrong
2019.12.30 00:55:15
2019.10.30 00:55:16
wrong
2019.12.30 00:55:15
2019.10.30 00:55:16
right (note 2018 instead of 2019 for the first one)
2018.12.29 23:55:15
2019.10.29 23:55:16
DateTime.TimeFormat = "HH:mm:ss"
DateTime.DateFormat = "yyyy.MM.dd" '<---- yyyy instead of YYYY
Ticks 1546127715000 ==> 2018.12.30 00:55:15
Ticks 1572393316601 ==> 2019.10.30 00:55:16
Yes, I noticed YYYY instead of yyyy but the result of my test (#2) does not change.4. As @alwaysbusy wrote the format is incorrect (there is also an extra space).
Sure? Your code does give me the correct dates with yyyy instead of YYYY:Yes, I noticed YYYY instead of yyyy but the result of my test (#2) does not change.
Ticks 1546127715000 ==> 2018.12.30 00:55:15 ' <----------- note it is 2018, not 2019 (with YYYY it gives 2019)
Ticks 1572393316601 ==> 2019.10.30 00:55:16
Since @alwaysbusy comment still raises some doubts in meSure? Your code does give me the correct dates with yyyy instead of YYYY:
DateTime.TimeFormat = "HH:mm:ss"
DateTime.DateFormat = "YYYY.MM.dd"
Log("YYYY.MM.dd")
Log ($"Ticks ${mm.Get("1")} ==> $DateTime{mm.Get("1")}"$)
Log ($"Ticks ${mm.Get("2")} ==> $DateTime{mm.Get("2")}"$)
DateTime.DateFormat = "yyyy.MM.dd"
Log("yyyy.MM.dd")
Log ($"Ticks ${mm.Get("1")} ==> $DateTime{mm.Get("1")}"$)
Log ($"Ticks ${mm.Get("2")} ==> $DateTime{mm.Get("2")}"$)
Yes, I did not recognize the Format for the year is wrong. I changed and the problem was solved
3. Initializing an object before you assign a different object to the variable is a mistake.
This code?I removed to initialize of Lastaction. Does my mistake results in 2 objects?
Lastaction.Initialize
Lastaction = File.ReadMap (File.DirData(Me),"Lastaction.t4")
Tested anyway and...I think that in this case you don't need to inizialize the map, but you can, without any problem.
Sub AppStart (Args() As String)
Dim m As Map
m.Initialize
m.Put(1,1)
File.WriteMap(File.DirApp, "m", m)
Private mapX As Map
' mapX.Initialize
mapX = File.ReadMap(File.DirApp, "m")
Log(mapX.Get(1))
End Sub
I don't know what "Week year" means
An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term
True. But when you upload a project you should make it easier for the other developers to test it.If I use File.DirAssets then the file location is read only, right?
Yes, though it will not really hurt the performance. It is more of a "bad design".I removed to initialize of Lastaction. Does my mistake results in 2 objects?
Dim mapX As Map = File.ReadMap(...)
Which is the same I wrote... initialization, in THIS case, is not required (necessary)Best way:
B4X:Dim mapX As Map = File.ReadMap(...)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?