您可以使用
SimpleDateFormatclass设置日期格式。
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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)