栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在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);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/508020.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号