如何在Java ME中格式化日期?

如何在Java ME中格式化日期?,第1张

如何在Java ME中格式化日期

您可以使用

SimpleDateFormat
class设置日期格式。
http://download.oracle.com/javase/1,5.0/docs/api/java/text/SimpleDateFormat.html

我猜模式会是这样的:

SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy, h:ma");format.format(yourDate);

编辑Java ME;我读到Java ME规范中没有SimpleDateFormat类。所以我会尝试日历

首先将您的日期放入日历,然后获取所需的所有内容。更好的是使它成为一种方法

Calendar calendar = Calendar.getInstance();Date myDate = new Date(); // as an example, date of "now"calendar.setTime(myDate);int day = calendar.get(Calendar.DAY_OF_MONTH);int monthNumber = calendar.get(Calendar.MONTH);String[] _months = new DateFormatSymbols().getMonths();String[] months = new String[12];for(int i =0; i < 12; i++){    months[i] = _months[i];}//because there is something wrong, we have a 12. month in the name of "" (nothing)//or if there is no DateFormatSymbols class in your plans//you may write for yourself;String month = months[monthNumber]; //or String month = monthNames[monthNumber];int year = calendar.get(Calendar.YEAR);int hour = calendar.get(Calendar.HOUR);int minute = calendar.get(Calendar.MINUTE);String amPm = calendar.get(Calendar.AM_PM)==1 ? "am" : "pm";System.out.println(day + " " + month + " " +     year + ", " + hour + ":" + minute + amPm);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5500404.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存