从Android中的Date对象获取星期几的值? [英] Get value of day month from Date object in Android?

查看:567
本文介绍了从Android中的Date对象获取星期几的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = format.parse(dtStart);
return date;

我已经按日期对象转换了字符串日期并获得了值:

I have converted the String Date by Date Object and get the value:

2013年2月17日星期日格林尼治标准时间

Sun Feb 17 07:00:00 GMT 2013

现在我要从此处提取日期(星期日/星期一)和月份.

Now I want to extract day (Sunday/Monday) and month from here.

推荐答案

import android.text.format.DateFormat;

String dayOfTheWeek = (String) DateFormat.format("EEEE", date); // Thursday
String day          = (String) DateFormat.format("dd",   date); // 20
String monthString  = (String) DateFormat.format("MMM",  date); // Jun
String monthNumber  = (String) DateFormat.format("MM",   date); // 06
String year         = (String) DateFormat.format("yyyy", date); // 2013

这篇关于从Android中的Date对象获取星期几的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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