我以字符串"dd-MM-yyyy hh:mm:ss"的形式输入日期到我的sqlite数据库。我已经把它作为一个字符串数组,并把它发送到一个图形活动。在图形活动中,我试图将其转换为日期对象,格式为"dd-MM-yyyy hh:mm:ss",但我只能将其转换为这种特定格式星期三1月15日03:54:30 GMT+05:30 2014,由于我无法显示我的图形。如何将其转换为日期格式"dd-MM-yyyy hh:mm:ss"
<<p> 服务活动/strong>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();
}
<<p> 图活动/strong> 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
使用SimpleDateFormat.format(Date)
,这将使String
在所需的格式:
df.format(dateArray[i])