如何获得一天从Android的指定日期 [英] How to get day from specified date in android

查看:90
本文介绍了如何获得一天从Android的指定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我的日期
2013年2月1日

Suppose my date is 02-01-2013

和它存储在变量
字符串strDate =2013年2月1日;

and it stored in variable String strDate="02-01-2013";

那我应该怎么得到这个日期的当天(即星期二)

then how should i get day of this date (i.e TUESDAY)

请帮我出
提前thnks

please help me out thnks in advance

推荐答案

使用的日历类是从的Java API。

Use Calendar class from java api.

Calendar calendar = new GregorianCalendar(2008, 01, 01); // Note that Month value is 0-based. e.g., 0 for January.
int reslut = calendar.get(Calendar.DAY_OF_WEEK);
switch (result) {
case Calendar.MONDAY:
    System.out.println("It's Monday !");
    break;
}

您也可以使用 SimpleDateFormater 解析日期日期

Date date = new Date();
SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd");
try {
    date = date_format.parse("2008-01-01");
} catch (ParseException e) {
    e.printStackTrace();
}

calendar.setTime(date);

这篇关于如何获得一天从Android的指定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆