Android Question device time

jchal

Active Member
Licensed User
Longtime User
i am using this
B4X:
 mytime=DateTime.Time(DateTime.Now)
first i dont get the correct time i need the device time
 

JCO

Active Member
Licensed User
Longtime User
i am using this
B4X:
 mytime=DateTime.Time(DateTime.Now)
first i dont get the correct time i need the device time
Time is returned as Ticks.
If you want it in a specific format, you can use something like:
B4X:
DateTime.DateFormat = "HH:mm:ss"
mytime=DateTime.Date(DateTime.Now)
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
i have done this but the device has time e.g 02:01:00 and it shows 01:06:00
in the next loop it makes afre 20 seconts or even after 1 minuta the time does not change
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
Log(DateTime.TimeZoneOffset) 2 and Log(DateTime.Now) 1488382549228
the time the device dysplaying is 5:36 the device is a samsung duos but i tested with a few other devices and i get the same thing
 
Last edited:
Upvote 0

corwin42

Expert
Licensed User
Longtime User
it gives 16:03 and the time is 16:36 on the phone

What DateTime.TimeFormat did you set? I guess "HH:MM" which is wrong because MM is for the month. So using this timeformat you will get 16:03 for 16:36 (03 for march).
Use DateTime.TimeFormat = "HH:mm")
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Or can it be...

I sometimes educate Oracle SQL and when the students do exercises about database date and time functions a wrong format mask is the most common mistake the students do. In SQL there is a similar trap in the format masks ("mm" for month and "mi" for minute).
Let's see what @jchal will report. :)
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
on the new project i created according to erel sample everithing is ok time and date are dysplayed correct, what i am doing wrong on my project???
what i try to do is to store the date and time and the database
my code is the following
B4X:
Sub Service_Start (StartingIntent As Intent)
    DateTime.dateformat = "yyyy/MM/dd"
        DateTime.TimeFormat= "HH:MM:ss"

      StartServiceAt("", DateTime.now + 1 * DateTime.TicksPerMinute,True)
   
    
        mydate=DateTime.date(DateTime.now)
        mytime=DateTime.Time(DateTime.Now)
        Dim InsertNewPossition As HttpJob
   InsertNewPossition.Initialize("InsertNewPossition", Me)
 
   InsertNewPossition.download2("http://www.mydomain.com/store.php", Array As String ("action", "InsertNewPossition", "user_name", myusername, "date", mydate, "time", mytime))

End Sub
do you see any error???? because i dont and the time never changes 13:02, 13:02......13:02
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
on the new project i created according to erel sample everithing is ok time and date are dysplayed correct, what i am doing wrong on my project???
what i try to do is to store the date and time and the database
my code is the following
B4X:
Sub Service_Start (StartingIntent As Intent)
    DateTime.dateformat = "yyyy/MM/dd"
        DateTime.TimeFormat= "HH:MM:ss"

      StartServiceAt("", DateTime.now + 1 * DateTime.TicksPerMinute,True)
  
   
        mydate=DateTime.date(DateTime.now)
        mytime=DateTime.Time(DateTime.Now)
        Dim InsertNewPossition As HttpJob
   InsertNewPossition.Initialize("InsertNewPossition", Me)

   InsertNewPossition.download2("http://www.mydomain.com/store.php", Array As String ("action", "InsertNewPossition", "user_name", myusername, "date", mydate, "time", mytime))

End Sub
do you see any error???? because i dont and the time never changes 13:02, 13:02......13:02

TimeFormat ----> "HH:MM:ss"
As writed @corwin42 in #10
What DateTime.TimeFormat did you set? I guess "HH:MM" which is wrong because MM is for the month. So using this timeformat you will get 16:03 for 16:36 (03 for march).
Use DateTime.TimeFormat = "HH:mm")
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
on the new project i created according to erel sample everithing is ok time and date are dysplayed correct, what i am doing wrong on my project???
This is not what you wrote in your previous post:
it gives 16:03 and the time is 16:36 on the phone

This is not the correct way to ask the community to help you. You must be more accurate. I did check various things on multiple devices after you wrote that it didn't work.
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
sorry for this erel but it was not my fault, i did what you said and in the first place it gave me what i told you.
then i uninstaled b4a just incase and i was desapointed to be honest with you with the result, i knew i was doing something wrong but i did not know what it was...
what i did i copy and paste your code once more in the new instalation and the corect result was there.
then i run my project did and i change the Format to HH:mm and it worked , that is why i retruned and informed everybody that the problem was solved.
i appologize to everybody if i cause problems but this was not my intension.......
also you have to know that the support given in here it helped me a lot solving problems and creating mobile apps that with other more commecial products i will not be able to ......
 
Upvote 0
Top