我已经以字符串形式输入日期" dd-MM-yyyy hh:mm:ss"到我的sqlite数据库。我已将它全部作为String数组并将其发送到图形活动。在图表活动中,我尝试将其转换为日期对象,格式为" dd-MM-yyyy hh:mm:ss" ,但是我能够将它转换为特定格式Wed Jan 15 03:54:30 GMT + 05:30 2014,因此我无法显示我的图表。如何将其转换为日期格式" dd-MM-yyyy hh:mm:ss"
服务活动
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable(){
@Override
public void run() {
Intent tIntent=new Intent(getApplicationContext(),GraphActivity.class);
tIntent.putExtra("tempArray", TArray);
tIntent.putExtra("dateArray", TSArray);
startActivity(tIntent);
}
}).start();
}
图表活动
Bundle extras=getIntent().getExtras();
double[] TArray=extras.getDoubleArray("tempArray");
String[] TSArray=extras.getStringArray("dateArray");
int dateArraySize=TArray.length;
Date dateArray[]=new Date[TArray.length];
String[] targetArr = TSArray;
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
for (int i=0;i<TArray.length;i++)
{
try {
//converting String date to Date
Date result=df.parse(TSArray[i]);
dateArray[i]= result;
} catch (ParseException e) {
e.printStackTrace();
}
Log.d("dateArray",String.valueOf(dateArray[i]));
}
logcat的
05-15 16:38:56.991: D/TSArray(13743): 15-05-2014 04:37:04
05-15 16:38:56.991: D/TSArray(13743): 15-05-2014 04:38:56
05-15 16:38:58.151: D/TSArray(13743): 15-05-2014 04:37:04
05-15 16:38:58.151: D/TSArray(13743): 15-05-2014 04:38:56
05-15 16:38:58.151: D/TSArray(13743): 15-05-2014 04:38:58
05-15 16:38:58.861: D/TSArray(13743): 15-05-2014 04:37:04
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:37:04 GMT+05:30 2014
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:38:56 GMT+05:30 2014
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:38:58 GMT+05:30 2014
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:38:58 GMT+05:30 2014
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:38:59 GMT+05:30 2014
05-15 16:39:04.481: D/dateArray(13743): Thu May 15 04:39:00 GMT+05:30 2014
答案 0 :(得分:0)
使用SimpleDateFormat.format(Date)
,这将以所需格式制作String
:
df.format(dateArray[i])