java本地时间,在Java中获取正确的本地时间(日历)

I use this method to get local time:

Calendar cal = Calendar.getInstance();

String time= new SimpleDateFormat("dd MMM yyyy HH:mm:ss").format(cal.getTime());

My problem is that afternoon this method gives me back for example "11:15" but it is "23:15" already.

I hope my desc is not confusing.

I want to get back afternoon values like: 12:MM , 13:MM, 14:MM ..etc goes to 23:MM. . .

What should i change?

解决方案

Are you sure that the time on the PC or whatever you are using to program is correct?

Try using the Gregorian calendar:

new GregorianCalendar().getTime()

Make sure you have these imports:

import java.util.Date;

import java.util.GregorianCalendar;

Hope that helps.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值