Skip to content
sallar edited this page Feb 2, 2012 · 2 revisions

This is not the first piece of code to convert Jalali (Shamsi) date to gregorian date and vice versa. Many classes and functions have been written over years, but none of them support years higher than 2038 (php's date() limit). So I decided to write my own code on php5's new DateTime object. It's yet to be completed, but still it does many of the main features without a flaw, and it supports years up to 9999.

Features

  • Accepts all php's date() format characters
  • The option to enable/disable global Jalali conversion
  • The option to enable/disable global Farsi numbers conversion
  • Supports php's built-in timezones, eg. Tehran/Iran
  • Object oriented

Instructions

To use this class, you should include it in your php document and make a new instance of it.

<?php
require_once dirname(__FILE__) . '/jdatetime.class.php';
$date = new jDateTime(); //Creates a new instance

The jDateTime() constructor accepts 3 parameters:

<?php
$date = new jDateTime(true, true, 'Asia/Tehran');

The first parameter, enables/disables global Farsi number replacement. If it's set to true, all Latin numbers will be replaced with their Farsi representatives.
The second parameter, enables/disables global Jalali conversion. If it's set to true, everything will be converted to Jalali (Shamsi) date system, if not, everything will be executed just like php's default DateTime object.
The third parameter, defines the internal timezone to use. Default is set to none and uses server's default timezone.
All parameters are optional.

Will be filled soon.

Clone this wiki locally