2

I'm building a small webservice and the client is an android client. I must use dates and I want to save it in my database.

The server side is in PHP and the client is in Java. What format is the best to send date to PHP and how can I convert it easily ?

EDIT: When i say format, i'm not talking of the data format. Just the format of the date. Because the data are sent with JSON but the dates are passed as string.

I was thinking about the timestamp but it's not a good idea since we know its size limit...

Thanks.

3 Answers 3

3

@Gp2mv3 -

  1. jmort253 is correct: JSON is an excellent data interchange format. Go for it!

  2. You can use getTimeStamp()" on the PHP side

  3. You can convert a PHP timestamp to a Java long timestamp as follows:

    Date d=new Date((long)phpTimeStamp*1000);

PS: If you use timestamps, you must never assume the client and the server are in any way synchronized with each other.

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

1 Comment

Thanks, I'll try the timestamps. The synchronization isn't really important here. ;)
2

The main advantage of RESTful webservices is that you can easily send data from one application to another, using a common transport that both will understand.

Both XML and JSON have been used to facilitate communication between different applications, even if they're both written in different languages.

While XML is a great solution, JSON has been gaining traction as a strong option due to it's simplicity and out-of-the-box compatibility with JavaScript.

In Java, you could use a library called Jackson, which will serialize your classes into JSON and deserialize JSON strings back into Java classes.

Also, I'm not sure what you have against timestamps. Since they are long values, they should be really easy to work with in terms of date comparisons, and they should be easy to store since they're typically long values.

3 Comments

Yes, i'm using JSON but the dates aren't in the same format in PHP and in Java. So my question is how to convert them ?
You asked what format was the best to send the data. What format is the best to send date to PHP and how can I convert it easily ? Please try to be more clear so that we can give you the best possible answers.
Yes I just saw the lack of clarity of my question. I'll fix it.
0

the easiest and most common way to store is using timestamps.

you can anytime change this timestamp into the required format using DateFormat. i hope that helps.

Comments

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.