简体   繁体   中英

How to send Date object from flex to Java Restful Webservice using JSON

I am getting a problem while sending date to from flex to Java webservices

I am selecting a date from datefield and assigning it to dob field

var dob :Date = datefield.selectedDate;

when I convert this date object to JSON , it is resulting in JSON object as below which is not being accepted by Restfull Webservice in Java.

{"dob":{"fullYear":2015,"date":13,"hours":0,"month":6,"minutes":0,"milliseconds":0,"fullYearUTC":2015,"seconds":0,"monthUTC":6,"dateUTC":13,"hoursUTC":4,"minutesUTC":0,"secondsUTC":0,"millisecondsUTC":0,"time":1436760000000,"timezoneOffset":240,"day":1,"dayUTC":1}

Please help me out in solving this problem. Thanks in advance.

Have u tried JodaDateTime, I use this in my project and it works good. You will have to send date in ("2015-09-10T01:19:42-06") this format. The JodaDatime will conevert into date and then you get the time in millisecond.

FYI

  String inputDate = "2015-09-10T01:19:42-06";
    //JodaTime
    DateTime dt = DateTime.parse(inputDate);
    Date jdkDate = dt.toDate();
    if(dt.toString().endsWith("Z")) {
        String dateformat = dt.toString();
        dateformat = dateformat.substring(0, dateformat.length()-1) + "+0:00";
        System.out.println(dateformat);
        System.out.println("==========================================");
    }

        System.out.println(dt.toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM