我怎么会减去两个日期? MM / DD / YYYY [英] How would i subtract two dates? mm/dd/yyyy

查看:114
本文介绍了我怎么会减去两个日期? MM / DD / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Android和Java的初学者,与Java stynax的pretty深刻的理解。我由当前日期制作一个简单的应用程序,采用由当他们出生的用户一个日期,然后减去并告诉他们如何在旧天来计算(用户)。有什么办法,我可以去这样做?

im a android and java beginner, with a pretty solid understanding of the java stynax. I am making a simple app that takes a date by the user of when they were born, and subtracts that by the current date and tells (the user) how old they are measured in days. What are some ways i could go about doing this?

P.S。我已经有一个系统determing用户的出生日期。它采用了最新开关输入字段,然后保存日期到一个名为usrDate var和格式化日期字符串。

p.s. i already have a system for determing the users birth date. it uses a date imput field, then saves the date to a var called usrDate and formats the date to a string.

在此先感谢!

推荐答案

下面是例子:

try {
DateFormat df = new SimpleDateFormat("hh:mm:ss_yyyy.MM.dd");
Date date1 = new java.util.Date();
Date date2 = df.parse("00:00:00_2013.01.01");
long diff = date2.getTime() - date1.getTime();
Log.e("TEST" , date1.getTime() + " - " + date2.getTime() + " - " + diff);
} catch (ParseException e) {
    Log.e("TEST", "Exception", e);
}

date1: 1350921506492
date2: 1356994800000
diff: 6073293508

diff / 1000 / 60 / 60 / 24 = 70,292748935

与今天的日期和出生日期更换日期。

Replace the dates with the today's date and the date of birth.

这篇关于我怎么会减去两个日期? MM / DD / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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