Android Question Problem saving setting current DateandTime

trueboss323

Active Member
Licensed User
Longtime User
Here is what I am using to try to save the current date and time:
B4X:
'Saving
currentdatelbl.text = DateTime.now
StateManager.SetSetting("CurrentDate",currentdatalbl.Text)

'Loading
currentdatelbl.Text = StateManager.GetSetting("CurrentDate")

But when I try to load it, I get something like "1424645748955" , which I have no idea what it means. How can I change the format so it appears as mm/dd/yyy hh:mm:ss ?
 

mangojack

Expert
Licensed User
Longtime User
1424645748955 is the Date and Time measured in Ticks.

Search for DateFormat ..
 
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
Thanks, I did not realize that before.
I set my format as
DateTime.TimeFormat = "dd/MM/yyy KK:mm:ss a"

Now I'm not sure how to use it. Is this the correct way to put it? :
B4X:
'Saving
DateTime.TimeFormat = "dd/MM/yyy KK:mm:ss a"
currentdatelbl.text = DateTime.now
StateManager.SetSetting("CurrentDate",currentdatalbl.Text)

'Loading
DateTime.TimeFormat = "dd/MM/yyy KK:mm:ss a"
currentdatelbl.Text = StateManager.GetSetting("CurrentDate")
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
uselessly you can use
B4X:
 DateTime.Date(DateTime.now) & " " &DateTime.time(DateTime.now)
or use this function
B4X:
ConvertToDate(DateTime.now)
Sub ConvertToDate(sec As Long) As String
   Dim TempStr As String
   TempStr=NumberFormat(DateTime.GetDayOfMonth(sec),2,0)
   TempStr=TempStr & "/" & NumberFormat(DateTime.GetMonth(sec),2,0)
   TempStr=TempStr & "/" & DateTime.GetYear(sec)
   TempStr=TempStr & " " & NumberFormat(DateTime.GetHour(sec),2,0)
   TempStr=TempStr & ":" & NumberFormat(DateTime.GetMinute(sec),2,0)
   Return TempStr
End Sub
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
or use this function

Whats the point in reinventing the wheel?

Java provides functions to format dates. They are really flexyble, and much more efficient than doing it manually.

I posted the string formats in the forums a couple times.

The correct answer to this problem has been aswered in here, you can use the search function to find it.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…