By Using this code :
使用此代码:
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 ... ------> Sun Feb 17 07:00:00 GMT 2013 <---------------
我已经按日期对象转换了字符串日期并获得了价值... ------> Sun Feb 17 07:00:00 GMT 2013 <---------------
Now i want to Extract Day (Sunday /Monday ) and Month form here any help ????
现在我想提取日(星期日/星期一)和月形式这里任何帮助????
3 个解决方案
#1
126
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
#2
13
You can try:
你可以试试:
String input_date="01/08/2012";
SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
Date dt1=format1.parse(input_date);
DateFormat format2=new SimpleDateFormat("EEEE");
String finalDay=format2.format(dt1);
Also try this:
也试试这个:
Calendar c = Calendar.getInstance();
c.setTime(yourDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
#3
3
to custom days of week you can use this function
到一周的自定义日期,您可以使用此功能
public static String getDayFromDateString(String stringDate,String dateTimeFormat)
{
String[] daysArray = new String[] {"saturday","sunday","monday","tuesday","wednesday","thursday","friday"};
String day = "";
int dayOfWeek =0;
//dateTimeFormat = yyyy-MM-dd HH:mm:ss
SimpleDateFormat formatter = new SimpleDateFormat(dateTimeFormat);
Date date;
try {
date = formatter.parse(stringDate);
Calendar c = Calendar.getInstance();
c.setTime(date);
dayOfWeek = c.get(Calendar.DAY_OF_WEEK)-1;
if (dayOfWeek < 0) {
dayOfWeek += 7;
}
day = daysArray[dayOfWeek];
} catch (Exception e) {
e.printStackTrace();
}
return day;
}
dateTimeFormat for example dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
dateTimeFormat例如dateTimeFormat =“yyyy-MM-dd HH:mm:ss”;
#1
126
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
#2
13
You can try:
你可以试试:
String input_date="01/08/2012";
SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
Date dt1=format1.parse(input_date);
DateFormat format2=new SimpleDateFormat("EEEE");
String finalDay=format2.format(dt1);
Also try this:
也试试这个:
Calendar c = Calendar.getInstance();
c.setTime(yourDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
#3
3
to custom days of week you can use this function
到一周的自定义日期,您可以使用此功能
public static String getDayFromDateString(String stringDate,String dateTimeFormat)
{
String[] daysArray = new String[] {"saturday","sunday","monday","tuesday","wednesday","thursday","friday"};
String day = "";
int dayOfWeek =0;
//dateTimeFormat = yyyy-MM-dd HH:mm:ss
SimpleDateFormat formatter = new SimpleDateFormat(dateTimeFormat);
Date date;
try {
date = formatter.parse(stringDate);
Calendar c = Calendar.getInstance();
c.setTime(date);
dayOfWeek = c.get(Calendar.DAY_OF_WEEK)-1;
if (dayOfWeek < 0) {
dayOfWeek += 7;
}
day = daysArray[dayOfWeek];
} catch (Exception e) {
e.printStackTrace();
}
return day;
}
dateTimeFormat for example dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
dateTimeFormat例如dateTimeFormat =“yyyy-MM-dd HH:mm:ss”;