From The Blog

PHP: Problem getting date in different locale

26 November 2013, in

Have you ever faced a problem trying to get date in another locale ?

The way you can do it right is as follows:

You will use set setlocale(), strftime()

suppose you want to get the date in Italian

setlocale(LC_ALL, 'it_IT'); // Set locale to Italian

echo strftime("%e %B %Y"); //today's date

echo strftime("%e %B %Y",strtotime($date)); //another date

Post a Comment

Javascript: Easily calculate difference between two dates in days

1 September 2012, in
Date.daysBetween = function( date1, date2 ) {
  //Get 1 day in milliseconds
  var one_day=1000*60*60*24;

  // Convert both dates to milliseconds
  var date1_ms = date1.getTime();
  var date2_ms = date2.getTime();

  // Calculate the difference in milliseconds
  var difference_ms = date2_ms - date1_ms;

  // Convert back to days and return
  return Math.round(difference_ms/one_day); 

//date1 and date2 are Date objects

Post a Comment