setting date and time

+2 bobo nakama · January 31, 2015
I want to output the date and time in french.can anyone help me out ?????

Post a Reply

Replies

Oldest  Newest  Rating
0 bobo nakama · February 1, 2015
yes.i can only output the date and time in english.i'm trying to do it in french
0 Jay Deshaun · February 1, 2015
Use strftime.
0 Jasmin Bakalović · February 2, 2015
What do you think about this: get month from local machine (English) and then translate it to French language using switch statement?

So, output will be "02 fevrier 2015 10h07".


// Get day, month and year from local machine
$day = date('d'); // 01 trough 31
$month = date('M'); // Jan trough Dec
$year = date('Y'); // 2015+

// Format months (translated from English to French)
switch($month) {
    
    case 'Jan':
        
        $month = 'janvier';
    break;
    
    case 'Feb':
    
        $month = 'fevrier';
    break;
    
    case 'Mar':
    
        $month = 'mars';
    break;
    
    case 'Apr':
        
        $month = 'avril';
    break;
    
    case 'May':
    
        $month = 'mai';
    break;
    
    case 'Jun':
    
        $month = 'juin';
    break;
    
    case 'Jul':
        
        $month = 'juillet';
    break;
    
    case 'Avg':
        
        $month = 'aout';
    break;
    
    case 'Sep':
        
        $month = 'septembre';
    break;
    
    case 'Oct':
        
        $month = 'october';
    break;
    
    case 'Nov':
        
        $month = 'novembre';
    break;
    
    case 'Dec':
        
        $month = 'decembre';
    break;
    
    default:
        
        $month = 'unknown';
    break;
}

// Get hours and minutes from local machine
$hours = date('H'); // 00 trough 23
$minutes = date('i'); // 00 trough 59

// Print date and time
echo $day.' '.$month.' '.$year.' '.$hours.'h'.$minutes;
0 Jay Deshaun · February 2, 2015
Why didn't you just use an array?
It's less memory consuming...

This should do the same thing:
// Get day, month and year from local machine
$day = date('d'); // 01 trough 31
$month = date('M'); // Jan trough Dec
$year = date('Y'); // 2015+

// Format months (translated from English to French)
$months = [
'Jan'=>'janvier',
'Feb'=>'fevrier',
'Mar'=>'mars',
'Apr'=>'avril',
'May'=>'mai',
'Jun'=>'juin',
'Jul'=>'juillet',
'Avg'=>'aout',
'Sep'=>'septembre',
'Oct'=>'october',
'Nov'=>'novembre',
'Dec'=>'decembre'
];

// Get hours and minutes from local machine
$hours = date('H'); // 00 trough 23
$minutes = date('i'); // 00 trough 59

// Print date and time
echo "$day {$months[month]} $year $hours h $minutes";
0 bobo nakama · February 3, 2015
thanks guys
that was very useful
0 Jay Deshaun · February 1, 2015
Do you mean like this link ?
0 bobo nakama · February 4, 2015
how can i install the locale fr-FR to my machine??
  • 1

PHP

107,161 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators