0

I had this weird problem a little while ago and haven't been able to find a solution yet. In my application, I keep some information about the activity of the user on my server. I also keep the date of the activity using getdate() function of PHP. When queried, I send this information back to the phone and try to represent the date in a more human-readable format.

For example,

//This is the part that runs on the server
$timeOfAct = getdate();
//$timeOfAct = 1339637005. I guess this is the date in milliseconds
//INSERT $timeOfAct to database

I send this information back to the application using JSON.

//st="1339637005"
SimpleDateFormat ft = new SimpleDateFormat("MM/dd/yyyy");
Date resultdate = new Date(Long.parseLong(st));
st=ft.format(resultdate);

st always becomes 01/16/1970.

As far as I understand, date 0 for JAVA is not equal to 0 for PHP.

So, do you have any suggestions for me to achieve a successful conversion?

UPDATE: I forgot to mention that I was using the 0th element of the array returned by getdate() which is equal to what is returned by time() function

//E.g. INSERT $timeOfAct[0]

3
  • 1
    getdate returns an array. Are you sure you're using it appropriately? Commented Jun 14, 2012 at 1:57
  • No I am not sure, actually. I am going to check it. Thanks. Commented Jun 14, 2012 at 2:09
  • Surprisingly, I was using it appropriately. I was using the 0th element of the array ($timeOfAct[0]) Commented Jun 14, 2012 at 2:17

1 Answer 1

1

getdate() returns an associative array of information related to the timestamp, not what you guessed.

If you want timestamp, just use time().

Sign up to request clarification or add additional context in comments.

3 Comments

Shouldn't be time() * 1000?
I was using the 0th element in the array which indeed is equal to time(). I didn't know that at first but it seems so.
Sorry that was my bad. I have always assumed that getdate returns the time in ms. Whatever, thanks for your time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.