如何添加天进在android的日期 [英] How to add days into the date in android

查看:140
本文介绍了如何添加天进在android的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库,我得到的开始日期象2011-11-30(YYYY / MM / DD)format.and时间日期像40 days.How我可以计算的日子,让MM / DD / YYYY新的日期格式

In my database I am getting start date like 2011-11-30(yyyy/mm/dd)format.and duration date like 40 days.How can i calculate the days and get new date format of mm/dd/yyyy.

谁能帮我

感谢

推荐答案

您可以尝试这样的事情,

You can try something like this,

    String dt = "2012-01-04";  // Start date
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(sdf.parse(dt));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    c.add(Calendar.DATE, 40);  // number of days to add, can also use Calendar.DAY_OF_MONTH in place of Calendar.DATE
    SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd-yyyy");
    String output = sdf1.format(c.getTime()); 

这篇关于如何添加天进在android的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆