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

查看:29
本文介绍了以特定格式显示 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

但我希望输出是

31/05/2011 

我需要在这里使用解析,因为日期需要按日期排序,而不是按字符串排序.

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天全站免登陆