32,000+ SUBSCRIBERS CAN'T GO WRONG !!!

phpans
GET TOP ARTICLES, SNIPPETS, SCRIPTS IN YOUR INBOX FOR FREE!

Delivered by GET EMAIL UPDATES FeedBurner
We always respect your privacy and take protecting it seriously.
We won't Spam You

Bangla date and time in PHP

, 0,
Bangla date and time in PHP
Some developer asked me about bangla date and time. A brother asked me “Is it possible to create bangla date and time?” I replied him “Sure why not?” php provides us all type facilities we can create any feauture as we wish. We can create bangla date and time using php. Today I am going to show you how to create bangla date and time. This code is orginally created by Tareq Hasan . This is the main function of the script. first create a file name as bnTime.php and write down this code into this file.
 <?php
class BanglaDate {
private $timestamp;
private $morning;
private $engHour;
private $engDate;
private $engMonth;
private $engYear;
private $bangDate;
private $bangMonth;
private $bangYear;
private $bn_months = array("পৌষ", "মাঘ", "ফাল্গুন", "চৈত্র", "বৈশাখ", "জ্যৈষ্ঠ", "আষাঢ়", "শ্রাবণ", "ভাদ্র", "আশ্বিন", "কার্তিক", "অগ্রহায়ণ");
private $bn_month_dates = array(30,30,30,30,31,31,31,31,31,30,30,30);
private $bn_month_middate = array(13,12,14,13,14,14,15,15,15,15,14,14);
private $lipyearindex = 3;
function __construct( $timestamp, $hour = 6 ) {
$this->BanglaDate( $timestamp, $hour );
}
function BanglaDate( $timestamp, $hour = 6 ) {
$this->engDate = date( 'd', $timestamp );
$this->engMonth = date( 'm', $timestamp );
$this->engYear = date( 'Y', $timestamp );
$this->morning = $hour;
$this->engHour = date( 'G', $timestamp );
//calculate the bangla date
$this->calculate_date();
//now call calculate_year for setting the bangla year
$this->calculate_year();
//convert english numbers to Bangla
$this->convert();
}
function set_time( $timestamp, $hour = 6 ) {
$this->BanglaDate( $timestamp, $hour );
}
private function calculate_date() {
$this->bangDate = $this->engDate - $this->bn_month_middate[$this->engMonth - 1];
if ($this->engHour < $this->morning)
$this->bangDate -= 1;

if (($this->engDate <= $this->bn_month_middate[$this->engMonth - 1]) || ($this->engDate == $this->bn_month_middate[$this->engMonth - 1] + 1 && $this->engHour < $this->morning) ) {
$this->bangDate += $this->bn_month_dates[$this->engMonth - 1];
if ($this->is_leapyear() && $this->lipyearindex == $this->engMonth)
$this->bangDate += 1;
$this->bangMonth = $this->bn_months[$this->engMonth - 1];
}
else{
$this->bangMonth = $this->bn_months[($this->engMonth)%12];
}
}
function is_leapyear() {
if ( $this->engYear % 400 == 0 || ($this->engYear % 100 != 0 && $this->engYear % 4 == 0) )
return true;
else
return false;
}
function calculate_year() {
$this->bangYear = $this->engYear - 593;
if (($this->engMonth < 4) || (($this->engMonth == 4) && (($this->engDate < 14) || ($this->engDate == 14 && $this->engHour < $this->morning))))
$this->bangYear -= 1;
}
function bangla_number( $int ) {
$engNumber = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
$bangNumber = array('১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০');
$converted = str_replace( $engNumber, $bangNumber, $int );
return $converted;
}
function convert() {
$this->bangDate = $this->bangla_number( $this->bangDate );
$this->bangYear = $this->bangla_number( $this->bangYear );
}
function get_date() {
return array($this->bangDate, $this->bangMonth, $this->bangYear);
}
}
function BDdate($time)
{
$bn = new BanglaDate($time);
$output = $bn->get_date();
$ReadyDate = "$output[0] $output[1] $output[2]";
return $ReadyDate;
}
?>

We have created our function successfully now this is fully ready for use. Let’s see how we run this. We are going to create a new file name as index.php and write down this code
index.php
<?php
include('bnTime.php');
$time = time();
$Bdate = BDdate($time);
echo $Bdate;
?>

Now run this script into your server this server will execute bangla date and time. I hope this article is helpfull for you. If you have any question about this article you can comment bellow this article.

Download PDF
Is this article helpful for you?





captcha

  • Connect
  •       
Top
Create an free account and start learning & sharing! Sign Up