How get the current time?

How get the current time?

Jorge San Martin發表於
Number of replies: 8
Hello,
I'm new here and I need some help.

I need get the current time, but using the date("Hi") function get one hour less. (at 12:00 I get 11:00)

I have the same problem with the chat module and I setup the timezone of my country and work fine.

Maybe I must use another date function to apply the timezone? What function it's used on the chat module to show the time? I don't find it.

Thank you very much

Jorge
評比平均分數: -
In reply to Jorge San Martin

Re: How get the current time?

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
$time = time(); // this will get you the current time in unix time format (seconds since 1/1/1970 GMT)

echo userdate($time, '%H:%M'); // this will print the time in the timezone of the current user (formats)
In reply to Martin Dougiamas

Re: How get the current time?

Vitor Torres發表於
Hello Martin,

Do you know any Moodle function to give the current day and month?
Looking forward for an answer.

Peace,
Vitor
In reply to Vitor Torres

Re: How get the current time?

Peter Bloomfield發表於
Hello Vitor,

Is there a particular reason you need to use a Moodle function? PHP has excellent date and time functions built-in (although it can take a while to get familiar with them). The date() function is very flexible, for example.

However, if you need the Moodle timezone, then the Moodle userdate() function already mentioned is ideal. The format string is the same as for PHP's strftime() function.

-Peter
In reply to Peter Bloomfield

Re: How get the current time?

Shreyas Patankar發表於

Hello everyone,

I am new to php programming.Can we create a block on moodle which would display "good morning", "good evening" messages based on user's time.

Please help.


-Shreyas

In reply to Shreyas Patankar

Re: How get the current time?

AL Rachels發表於
Core developers的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片

I think that would be another fairly simple thing to do using the Generico filter.  I've been using it for a year or so to personalize greetings and other messages to students throughout the various courses and parts of Moodle. Go to this forum discussion and ask: https://moodle.org/mod/forum/discuss.php?d=324771#p1335240