我的日期为字符串“18.07.2013 15:31:10”,我希望它像
一样分开string DAY_OF_WEEK_IN_MONTH = "18";
string DAY_OF_WEEK = "Thursday";
string MONTH_IN_YEAR = "July";
string HOUR ="15:31";
我该怎么做?我看过格式化帖子,但不知道如何分割日期。
答案 0 :(得分:1)
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date date = format.parse("18.07.2013 15:31:10");
Calendar calendar = Calendar.getInstance();
calenadr.setTime(date);
然后您可以使用calendar
获取所需信息。
int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH);
答案 1 :(得分:0)
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date date = format.parse("18.07.2013 15:31:10");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
System.out.println("day:" + day);
System.out.println("month :"+month);
System.out.println("year: "+year);
System.out.println(new SimpleDateFormat("MMM").format(cal.getTime()));
System.out.println(new SimpleDateFormat("EEE").format(cal.getTime()));
System.out.println(new SimpleDateFormat("HH:mm").format(cal.getTime()));