android


How to subtract two calendar object in Android


Say for example I have two calendar object with the format of "MM/dd/yyyy". How do I subtract them and should return the number of days? For example, "9/7/2014" - "9/1/2014" and returns 7.
Calendar calendar = Calendar.getInstance();
Calendar today = Calendar.getInstance();
You may try like this:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,7);
calendar.set(Calendar.MONTH,8);
calendar.set(Calendar.YEAR, 2014);
Calendar today = Calendar.getInstance();
long difference = today.getTimeInMillis() - calendar.getTimeInMillis();
int days = (int) (difference/ (1000*60*60*24));

Related Links

override empty method in custom view and handle it in MainActivity
ClassNotFoundException: Of Module inside a library project's AAR file
Android: java.lang.NullPointerException at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:490)
How to set time range using seekbar
Rendering Problems on android studio: the following class could not be instantiated
Programmatically setting icon to navigation drawer menu item using drawable resource is always black in Android
DSP (Digital Sound Processing) with Android Media Player
AOSP layout xml file preview in eclipse
Sending a parameter from activity1 to Activity2
Android - Keep Service Running to keep Data in Storage
onCreateView is called after returning back from second activity
Cannot test app with android 5.1 device(Infinix hot note) on android studio 1.4 and 2.0
How can I fix this misbehavior of SwipeRefreshLayout
Why can't I reference the attr `android:popupEnterTransition`?
Poor recognition accuracy of Pocketsphinx using phoneme recognition on Android, French language
WeatherApp, setting an image inside and AsyncTask while parsing XML using setImageResource()

Categories

HOME
porting
apache-flink
character-encoding
swt
owl-carousel
appcelerator
google-cloud-functions
entity-framework-core
soa
simulink
square
settings
frontend
elasticsearch-5
g++
watson-conversation
plist
windows-ce
mautic
automatic-ref-counting
eip
qsqlquery
parameter-passing
coin3d
fileserver
google-data-studio
wolframalpha
topology
simpleitk
babel
pagespeed
beta
game-theory
syntax-highlighting
jackson-modules
outliers
inversion-of-control
soot
calculation
turfjs
github3.py
classcastexception
protege4
openerp-7
lint
wurfl
google-earth-engine
cin
numberpicker
odoo-website
laravel-elixir
memory-mapping
flask-login
httr
x++
fwrite
reportservice2010
tf
mongotemplate
modelsim
opengl-4
cup
cpu-cache
trigger.io
chromium-os
meteor-packages
reporting-services-2012
qtplugin
adafruit
macaulay2
mta
beamer
tooleap
appscale
nservicebus5
phpwebsocket
libvlc
.bash-profile
telepat
matlab-deployment
diff3
dbaccess
jbake
ray
tinyxml
spring-3
artemis
kendo-dataviz
unit-of-work
epiceditor
uimanageddocument
mapping-by-code
wiimote
matlab-load
rmdir
django-paypal
svk
uideviceorientation
cruisecontrol.rb
hbm2java
strtod
fdf

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App