如何转换yyyy-MM-dd格式的Utils.getDateBasedOnCurrentDate(mPosition)

时间:2016-05-18 04:40:47

标签: android android-studio

我正在尝试转换日期..........

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        cv::Mat matResultImage = [self findSquaresInImage:image];
    dispatch_async( dispatch_get_main_queue(), ^{

           self.imageView.image = [JKUtilityClass UIImageFromCVMat:matResultImage];
    });
});

但它给出了例外:

String date = null ; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'+'0530"); date = Utils.getDateBasedOnCurrentDate(mPosition); Date attendancedate = dateFormat.parse(date); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); date = format.format(attendancedate); Log.e("ddddddddddddddddddd", date); }catch (ParseException e){ e.printStackTrace(); }

2 个答案:

答案 0 :(得分:0)

使用

更改此行
 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'+'0530");

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

答案 1 :(得分:0)

试试这个答案:

SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();

       // String inputPattern = "EEE MMM d HH:mm:ss zzz yyyy";

        String outputPattern = "dd-MM-yyyy";

        //SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
        SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);

        //Date date = null;
        String str = null;

        try {
            String time = sdfDate.format(now);
            //date = inputFormat.parse(time);
            str = outputFormat.format(now);
            Log.i("mini1", "Converted Date Today:" + time);
            Log.i("mini", "Converted Date Today:" + str);
           // Toast.makeText(getApplicationContext(), str, 5000).show();
        } catch (ParseException e) {
            e.printStackTrace();
        }