mysql 转换为datetime类型,将MySql DateTime类型转换为更友好的东西

I have a Java web app that reads a MySql db and returns DateTime fields. What is the best way to convert the DateTime fields returned in the resultset into something more readable?

Currently the DateTime fields print as:

2008-12-14 16:30:00

but I would like something more user friendly like:

14 Dec 2008 at 16:30

I am populating an ArrayList with these dateTimes from a pojo. I would like to format them before adding to the arrayList, so then I can just print the contents of the arrayList in the JSP.

解决方案

Another option is to use the JSTL. The formatting library makes it easy to display a date in any format and it is i18n aware. The advantage is that you can leave the date as a Date object and manipulate it as such but only convert it when you need to display. The format tag will look like this:

Like I said above, one big advantage is that it is i18n aware so you can display the date in a localized format.

The full syntax is:

timeZone="expression"

type="field" dateStyle="style"

timeStyle="style"

pattern="expression"

var="name" scope="scope"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值