Android Question Problem saving setting current DateandTime

Discussion in 'Android Questions' started by trueboss323, Feb 22, 2015.

  1. trueboss323

    trueboss323 Active Member Licensed User

    Here is what I am using to try to save the current date and time:
    Code:
    '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 ?
     
  2. mangojack

    mangojack Well-Known Member Licensed User

    1424645748955 is the Date and Time measured in Ticks.

    Search for DateFormat ..
     
    DonManfred and Peter Simpson like this.
  3. trueboss323

    trueboss323 Active Member Licensed 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? :
    Code:
    '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")
     
  4. buras3

    buras3 Active Member Licensed User

    uselessly you can use
    Code:
    DateTime.Date(DateTime.now) & " " &DateTime.time(DateTime.now)
    or use this function
    Code:
    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
     
    DonManfred likes this.
  5. ivan.tellez

    ivan.tellez Active Member Licensed User

    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: Feb 23, 2015
    mangojack and DonManfred like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice