当前位置: 动力学知识库 > 问答 > 编程问答 >

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());
分享给朋友:
您可能感兴趣的文章:
随机阅读: