I have an app that checks for a new file on the internet. If the internet version is newer then the download takes place if not it is left. My problem is that i seem to be ab le to only check the files date not the time. So if i download a new file in the morning then i am unable to download a newer file that is placed ther in the afternoon because the timestamps seem to be the same.
This is the code I am using
B4X:
LocalFileStamp = DateTime.DateParse(DateTime.Date(File.LastModified(DeviceFolder & DeviceDirectory, ServerFileName)))
ServerFileStamp=DateTime.DateParse(DateTime.Date(Files(i).Timestamp))
If (LocalFileStamp<ServerFileStamp) Then
.....download
End If
the logs i put in were
Log(DateTime.Time(LocalFileStamp))
log(DateTime.Time(ServerFileStamp))
this gives me
09:23:28
03:30:00
so it just shows the time diff of the file. What i am trying to achive is to check if the file on the server against the file on the device so i need the time AND the date because there may be multiple uploads during the day,
Could you advise the correct code?
Thanks again
UPDATE:
if i use the following code it seems to work ok.
ServerFileStamp=Files(i).Timestamp + (3600000*17)
is this a legit solution that would work in all cases? How would i adjust for daylight saving time from MST to MDT?
How about this: If the server time 9:14:17, the local time is 6 hours later. You can even set the minutes and seconds. You could also work it the other way. If you know the local time and want to calculate the server time use -6 for the hours.
B4X:
Dim ServerFileStamp,LocalFileStamp As Long
Dim LocalTime As String
ServerFileStamp=DateTime.Now
LocalFileStamp= TimeAdd(ServerFileStamp,6,0,0) '6 hours later
LocalTime=DateTime.Time(LocalFileStamp)
Msgbox(LocalTime,"")
which uses the below sub:
B4X:
Sub TimeAdd(Ticks As Long, Hours As Int, Minutes As Int, Seconds As Int) As Long
Return Ticks + Hours * DateTime.TicksPerHour + Minutes * DateTime.TicksPerMinute + Seconds * DateTime.TicksPerSecond
End Sub