Axis2-日期格式 [英] Axis2 - Date Format

查看:120
本文介绍了Axis2-日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由Axis2作为对Web Service客户端的响应输出的日期格式被格式化为"2009-08-28 + 01:00".我想将其更改为仅显示不带时区信息的日期(例如:"2009-08-28")

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 only the date without the timezone information (e.g.:"2009-08-28")

第2轴1.4.1

<xsd:element name="StartDate" type="xsd:date" />;

问题

  • 是否可以更改Axis 2用于写入日期信息的输出格式?
  • .NET客户端遇到与此日期格式转换有关的任何问题吗?
  • Question

    • Is it possible to change the output format, which is used by Axis 2 to write date information?
    • Can you see any issues for .NET clients reagrding the conversion of this date format?
    • 很遗憾,无法将"StartDate"元素更改为xsd:stringxsd:token


      Unfortunately it is not possible to change the "StartDate" element to a xsd:string or xsd:token


      我正在使用xsd:date XML数据类型,该数据类型定义为

      As I am using the xsd:date XML Data Type which is defined as

      [-]CCYY-MM-DD[Z|(+|-)hh:mm]
      

      因此,如果我设置

      Calendar cal = Calendar.getInstance();
      cal.setTimeZone(TimeZone.getTimeZone("UTC");
      ...
      

      然后输出看起来像这样

      2009-01-28Z
      

      您可以将"UTC"替换为"GMT"或".

      You can replace "UTC" by "GMT" or "".

      我可以摆脱"Z"字吗?

      Can I get rid of the "Z"?

      推荐答案

      该问题是由于使用Calendar对象作为xsd:date字段的源值引起的.当您获得Calendar实例时,它总是与时区一起使用(如果未明确指定,则使用默认时区).要删除时区,请使用clear()方法并恢复除时区以外的所有字段.然后,XML映射库(我已经使用XmlBeans进行了测试,但是我认为对于Axis支持的其他绑定库也是如此)生成没有时区后缀的XML.

      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)
      );
      

      这篇关于Axis2-日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆