以特定格式显示Java.util.Date [英] display Java.util.Date in a specific format

查看:80
本文介绍了以特定格式显示Java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.parse("31/05/2011"));

给出输出

Tue May 31 00:00:00 SGT 2011

但是我想要输出

but I want the output to be

31/05/2011 

我需要在这里使用解析,因为日期需要排序为日期而不是String。

I need to use parse here because the dates need to be sorted as Dates and not as String.

任何想法??

推荐答案

如何:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.format(dateFormat.parse("31/05/2011")));

> 31/05/2011

这篇关于以特定格式显示Java.util.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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