Convert Jalali calendar to Gregorian by PHP in CodeIgniter
✔ Recommended Answer
It's generally better to stick to existing libs rather than writing your own one.Try, for example, jDateTime or Gregorian-Jalali-Date-Convertor.
P.S. I never tried to use them myself, but first one looks much more solid.
Source: stackoverflow.com
Answered By: borisano
To convert Jalali calendar to Gregorian calendar in PHP, you can use the jDateTime
library which provides convenient methods to convert between Jalali and Gregorian calendars. In CodeIgniter, you can include this library in your project and use it to perform the conversion.
Here are the steps to do so:
Download the
jDateTime
library from https://github.com/sallar/jDateTime and place it in your CodeIgniter project'sapplication/libraries
folder.Load the library in your CodeIgniter controller or model:
php$this->load->library('jdatetime');
- Use the
date
method of thejDateTime
class to convert a Jalali date to a Gregorian date:
php// Convert "1399-01-01" (Jalali date) to a Gregorian date
$gregorianDate = $this->jdatetime->date('Y-m-d', strtotime('1399-01-01'));
In this example, we use the date
method to convert the Jalali date 1399-01-01
to a Gregorian date. The second argument of the strtotime
function is used to convert the Jalali date to a Unix timestamp, which is then passed to the date
method.
Note that the jDateTime
library also provides other methods to format dates, parse dates, and perform other operations with Jalali and Gregorian calendars. You can consult the library's documentation for more information.
Comments
Post a Comment