从xmlGregorianCalender到具体格式 [英] From xmlGregorianCalender to date with specific format

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

问题描述

我有这个方法

public static Date toDate(XMLGregorianCalendar calendar) 
  if (calendar == null) {
    return null;
  }
  return calendar.toGregorianCalendar().getTime();
}

从此方法获取的日期是使用此格式 Fri May 30 12:00:00 EEST 2014 但是我的格式就像 dd-MM-yyyy HH:mm:ss any想法如何?

The date I get from this method is with this format Fri May 30 12:00:00 EEST 2014 but I wan the format to be like dd-MM-yyyy HH:mm:ss any idea how ??

推荐答案

尝试使用 SimpleDateFormat 根据需要格式化日期对象。

Try with SimpleDateFormat to format the date object as per your need.

DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(new Date()));

输出:

11-06-2014 21:13:49

你的默认值为code> toString()执行 Date 对象。

You are getting default toString() implementation of Date object.

查找源代码代码在这里日期#toString()使用 EEE MMM dd HH:mm:ss zzz yyyy pattern。

Find the source code here Date#toString() that uses EEE MMM dd HH:mm:ss zzz yyyy pattern.

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

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