tags:

views:

72

answers:

5

How do I get the system date and time in this format:

$systime="12/january/2010 10.30 AM " 
A: 

date() and time()

Chacha102
Really, just date(). time() isn't necessary.
Frank Farmer
+4  A: 

To get exactly what you've asked for, you'll need to use strtolower() and date:

$systime = strtolower(date("d/F/Y G.i")) . " " . date("A") . " ";

You need strtolower because there's no built-in way to get lowercase month values, so you need to get that part as January and then transform it to lowercase. You can't lowercase the whole thing because you seem to want AM or PM rather than am or pm.

Dominic Rodger
Mr Dominic , Thank you very much....when I run it I get the out put as 05/march/2010 06/29/46AMpls see the time part.. now it is 12.02 PM at india...which is not displayed... can u pls help me..
Flins
time is not getting... Thnak you for your help.
Flins
@Flins - sorry, what do you mean by "time is not getting"?
Dominic Rodger
Time is not getting displayed correctly. It does not print my system time. Thank you
Flins
+1  A: 

Try:

$systime = date('d/F/o g i A');

Sample output:

05/March/2010 7 27 AM
codaddict
thnk u very much....I got the out put as 05/March/2010 6 36 AM but my system time is 12.07 PM. Indian stadard time...date is correct but time part is not.....can u pls help...
Flins
Just to be clear...you are in India and where is your server ? :)
codaddict
Thank you for your reply,I am sorry ,, I dont undestand which server you are asking about..Am developing a web site, so now it runs on my laptop only...
Flins
Let us know your timezone using echo date('T');
codaddict
UTCthis is what I get when executing echo date('T')
Flins
Now thats GMT, which is 5 and 1/2 hours behind IST which is why you are getting a time 5 and half hours behind. I'm not sure how to correct that...may be you can try setting the timezone explicitly like: date_default_timezone_set('Asia/Calcutta');
codaddict
thnk you very much.....
Flins
+2  A: 

Using date and strftime() we can get the system date.

Example:

echo date("d/F/Y g:i A");//It prints 05/March/2010 12:18 PM

echo strftime("%d/%B/%Y %I:%M %p"); //It prints  05/March/2010 12:20 PM
rekha_sri
thnk u rekha... how do we get the current time displayed in 12hrs format(AM and PM)
Flins
A: 

http://stackoverflow.com/questions/2385106/get-system-time-using-php

Why do you ask your question 2 times ??

Marco