Android Display date from one week to another like (Thursday to Thursday )

后端 未结 3 1969
轮回少年
轮回少年 2021-01-16 01:30

I have been stuck on this issue for the last two days. My issue is this: how can I display the date from one week to another week (Thursday to Thursday)? For example:

<
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 02:02

    try this,

    String start_date = "01-30-2014";  // Start date
                        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                        Calendar cal = Calendar.getInstance();
                        try {
                            c.setTime(sdf.parse(start_date));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        cal.add(Calendar.DATE, 7);  // number of days to add,in your case its 7
                        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy");
                        String to_date = sdf1.format(cal.getTime()); 
    

    Actually i don't like android Calendar( I prefer Joda-Time) but above solution should work for you

提交回复
热议问题