Is there something like TimeSpan in android development?

后端 未结 6 506
盖世英雄少女心
盖世英雄少女心 2021-01-12 05:29

I need to know if there is something like a timespan in android development?

in C# there is something like and I like to use it in two ways:

  1. generate a
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 06:24

    public long addSeconds(long dt,int sec) //method to add seconds in time  
    {
    
        Date Dt = new Date(dt);
        Calendar cal = new GregorianCalendar();
    
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
        sdf.setCalendar(cal);
        cal.setTimeInMillis(Dt.getTime());
        cal.add(Calendar.SECOND, sec);
        return cal.getTime().getTime();
    
    } 
    

    pass date and time in sec, it will return modified time...

提交回复
热议问题