Axis2 - Date Format

后端 未结 4 1543
小蘑菇
小蘑菇 2021-02-06 05:00

Scenario

The date format which is output as a response to the Web Service client by Axis2 is formatted as \"2009-08-28+01:00\". I would like to change this to show on

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 05:33

    The problem is caused by using Calendar object as a source value for xsd:date field. When you get instance of Calendar it always goes with timezone (default timezone is used if not specified explicitly). To remove timezone use clear() method and restore all fields excluding timezone. Then XML mapping library (I tested with XmlBeans, but I think it's also true for other binding libraries supported by Axis) generates XML without timezone suffix.

    Calendar myDate = Calendar.getInstance();   // returns GregorianCalendar
    Calendar now = (Calendar)myDate.clone();    // save current timestamp
    myDate.clear(); // this clears the fields, including Calendar.ZONE_OFFSET
    myDate.set(     //set all fields back from the saved copy
        now.get(Calendar.YEAR),
        now.get(Calendar.MONTH),
        now.get(Calendar.DAY_OF_MONTH),
        now.get(Calendar.HOUR_OF_DAY),
        now.get(Calendar.MINUTE),
        now.get(Calendar.SECOND)
    );
    

提交回复
热议问题