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

How to track user interaction when a dialog is shown?
Way to drag listview items till middle when reached bottom
how to make a connection via bluetooth with phonegap 3.5.0 to an Arduino?
How can I limit the length of content in the webview?
How to print out all contents of Facebook GraphUser object on Android?
Save google map for offline use
How to apply Undo and Redo operation to EditText on Button click in android
Load image from file on HTC
What are the specific conditions that cause Unity3D's AndroidJavaClass to throw on new?
I want to set the dimension dynamically from the layout file, is it possible to load the action bar size in dimension file?
XEP-0167, libjingle_peerconnection.jar and my application
Pass specific TouchEvent to specific view
Android ImageButton - How to hide the image while showing the background?
How to add an ImageLoader in android
how to select multiple items in a listview populated from ArrayList in Android
Change menu text android

Categories

HOME
android
phantom-dsl
httparty
merge
static
limit
gluon-mobile
extjs4.2
enthought
windows-ce
resultset
google-form
heat
aws-sdk
scriptella
gpio
mql
sqsh
scrollview
python-2.6
rselenium
engine.io
cd
ods
linq-to-objects
tasm
azure-arm
subclipse
print-css
plr
outputcache
libgphoto2
automapper-5
serde
tinkerpop
subnet
type-theory
offline.js
ampps
change-tracking
vcloud-director-rest-api
ziparchive
xcode-server
uicolor
html-to-pdf
pushbots
ascii-art
character-replacement
linklabel
xvim
google-books
evolus-pencil
airbrake
avahi
dnssec
mraid
at-job
psr-4
rmysql
jama
ios8-extension
draw2d-js
mutual-authentication
drupal-nodes
model-driven-development
printdialog
neos-server
qi4j
monotouch.dialog
user-tracking
u2netdk
event-receiver
cloudfiles
diagrams
resharper-6.0
globals
qtabbar
change-management
leader
idatareader

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