android开发中是否有类似TimeSpan的东西? [英] Is there something like TimeSpan in android development?

查看:129
本文介绍了android开发中是否有类似TimeSpan的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道android开发中是否存在时间跨度?

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

在C#中有类似的东西,我喜欢以两种方式使用它:

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

  1. 生成时间跨度,然后添加例如分钟,然后显示整个跨度
  2. 生成两个DateTime之间的时间跨度(android中的DateTime等价于什么?)

推荐答案

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...

这篇关于android开发中是否有类似TimeSpan的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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