Home Sending DATE/TIMESTAMP from device to REST service
Reply: 2

Sending DATE/TIMESTAMP from device to REST service

AndroidBeginner2018 Published in 2018-02-14 10:43:22Z

I am trying to send a date and time to my SQL oracle database through my REST service. However, the field in the SQL database is getting null.

Here is my code to get the date and time:

 public void getCurrentDateandTime() throws ParseException {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    currentDateandTime = dateFormat.format(c.getTime());
    CDAT = dateFormat.parse(currentDateandTime);

In my REST service, this field is specified as a date datatype, however my the temporal I am using is TIMESTAMP as I want to get the date and time.

When I use postman sending through test data like this:

"createdTimestamp": "2018-02-12T09:27:39"

It is being received and shown in my SQL database.

Why is the date I am sending from Android receiving null?

M.Saad Lakhan
M.Saad Lakhan Reply to 2018-02-14 11:53:17Z

Try this buddy:

    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());

And then send this formattedDate string. Make it string type and then parse your string as datetime object. Hope this works. Happy Coding :)

Kris Rice
Kris Rice Reply to 2018-02-14 19:02:25Z

Most REST APIs stick with iso8601 format as a standard.

The java code would be like:

TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); 
String nowAsISO = df.format(new Date());

Then in Oracle to get back is:

to_timestamp('2018-02-14T00:00:00.000Z', 'YYYY-MM-DD"T"HH24:MI:SS.ff3"Z"')
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.488007 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO