date

Calculating the difference between dates in Java

Calculating the difference in days between two dates in Java sounds like a trivial task, but it turns out to be otherwise. To keep track of time, Java counts the number of milliseconds from the start of January 1, 1970 and this is called the epoch. Many programmers then think that subtracting the millisecond timestamps of two moments and dividing by the number of milliseconds per day is the right way to calculate the difference between two dates. The code below is as simple as it could be, but it is also as wrong. Here is why:

  

Change Default Date Format in Ruby on Rails

Just a quick and simple hint!
 
If you need to set the default formatting of dates throughout your whole application in Ruby on Rails, just add the following line to your "<your application>/config/environment.rb"
 
 
my_date_formats = { :default => '%d/%m/%Y' } ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_date_formats) ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(my_date_formats)
 

Syndicate content