微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 在添加时间时需要24小时格式获取时间

我写了一个添加间的功能,如下所示
private void Delay15Minute() {
        String pkManifest = manifest.pkManifestNo;
        manifest_helper = new manifest_helper(this);
        cursor = manifest_helper.GetDeliveries(pkManifest);
        cursor.movetoFirst();
        for (int i = 0; i < cursor.getCount(); i++) {
            cursor.getString(cursor.getColumnIndex("PKDelivery"));
            // String
            // RevisedTime=cursor.getString(cursor.getColumnIndex("RevisedEstimatedDeliveryTime"));
            String RevisedTime = "12:55";

            // get hour and minute from time string
            StringTokenizer st1 = new StringTokenizer(RevisedTime,":");
            int j = 0;
            int[] val = new int[st1.countTokens()];
            // iterate through tokens
            while (st1.hasMoretokens()) {
                val[j] = Integer.parseInt(st1.nextToken());
                j++;
            }
            // call time add method with current hour,minute and minutesToAdd,// return added time as a string
            String date = addTime(val[0],val[1],15);
            // Tioast the new time
            Toast.makeText(this,"date is =" + date,Toast.LENGTH_SHORT).show();

        }
            }



public String addTime(int hour,int minute,int minutesToAdd) {
        Calendar calendar = new GregorianCalendar(1990,1,hour,minute);
        calendar.add(Calendar.MINUTE,minutesToAdd);
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
        String date = sdf.format(calendar.getTime());

        return date;
    }

我正在从01:10得到这个爆发,从12点开始…

我需要得到它的13:10格式,即24小时格式…..请帮助我

解决方法

您在SimpleDateFormat模式中使用了hh.这是12小时的格式.使用kk代替,这样可以让您以24小时格式显示当天的时间.见 SimpleDateFormat.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐