Convert seconds to days, minutes, and hours in Obj-c

后端 未结 11 2380
[愿得一人]
[愿得一人] 2020-12-13 01:16

In objective-c, how can I convert an integer (representing seconds) to days, minutes, an hours?

Thanks!

11条回答
  •  时光取名叫无心
    2020-12-13 01:57

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        Date dateObj1=null;
        Date dateObj2=null;
        try {
            // String format = "MM/dd/yyyy hh:mm:ss";
            dateObj1 = sdf.parse(Appconstant.One_One_time);
            dateObj2 = sdf.parse(Appconstant.One_Two_time);
            Log.e(TAG, "dateObj12" + dateObj1.toString() + "---" + dateObj2.toString());
            DecimalFormat crunchifyFormatter = new DecimalFormat("###,###");
            long diff = dateObj2.getTime() - dateObj1.getTime();
            /*int diffDays = (int) (diff / (24 * 60 * 60 * 1000));
            System.out.println("difference between days: " + diffDays);
            int diffhours = (int) (diff / (60 * 60 * 1000));
            System.out.println("difference between hours: "
                    + crunchifyFormatter.format(diffhours));
            int diffmin = (int) (diff / (60 * 1000));
            System.out.println("difference between minutes: "
                    + crunchifyFormatter.format(diffmin));*/
            int diffsec = (int) (diff / (1000));
            System.out.println("difference between seconds:"
                    + crunchifyFormatter.format(diffsec));
    

提交回复
热议问题