Jump to content

plus 9 hours to date/time php

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
the jil

the jil

    Newbie

  • Members
  • Pip
  • 4 posts
This is a little script to get the weekdays and the months in danish, when website is located on server in the US. But is it possible to add +9 hours to the time so that it will be the correct european (danish)time/date.

I was thinking about adding something to the getdate() line?? Can anyone help?

Thanks







<?php



function dagsdato()
{



$weekdays = array("Søndag","Mandag","Tirsdag","Onsdag",
"Torsdag","Fredag","Lørdag");


$month = array("januar","februar","marts","april","maj",
"juni","juli","august","september","oktober",
"november","december");


$dato_array = getdate();


return $weekdays[$dato_array[wday]] . " d. ". $dato_array[mday] . ". " .$month[($dato_array[mon]-1)] . " ".$dato_array[year];


}
?>

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
To just add 9 hours? Yea that's simple.

The date function actually accepts the time in seconds in the second non required field which shortcuts to now() if left empty. A function called "strtotime()" will output those seconds and accepts values like "+9 hours" or "-3 weeks" etc.

<?PHP
echo date('m/d/Y H:i:s', strtotime('+9 hours'));

I'm kinda guessing on the date format... that's from memory and I don't use that function often. But you get the idea.

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
also check out the function PHP: setlocale - Manual which can be handy, also, this function can be nice: PHP: DateTime::setTimezone - Manual

BlaineSch said:

To just add 9 hours? Yea that's simple.

The date function actually accepts the time in seconds in the second non required field which shortcuts to now() if left empty. A function called "strtotime()" will output those seconds and accepts values like "+9 hours" or "-3 weeks" etc.

<?PHP

echo date('m/d/Y H:i:s', strtotime('+9 hours'));


I'm kinda guessing on the date format... that's from memory and I don't use that function often. But you get the idea.

I think a dane would like a date formatted this way:

echo date('Y-m-d H:i:s', strtotime('+9 hours'));


__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
the jil

the jil

    Newbie

  • Members
  • Pip
  • 4 posts
Thank you so much, this did the trick!

$dato_array = getdate(strtotime('+9 hours'));
:thumbup1: