Jump to content

time() in seconds?


RON_ron

Recommended Posts

Do you mean aside from the help you've already gotten?

 

Your code has a syntax error in it, in addition to being logically incorrect.

 

-Dan

 

oh,  do you mean the dungeon master style riddles he's gotten so far? This is a PHP help forum with a lot of beginners in it. If all you want to do is send people to the user manual or point out that the code HAS errors (without offering a fix), why even bother replying?

 

Ron: Try something like the following code, but change the timezone ("Pacific/Nauru") to the one you need. They are listed here: http://www.php.net/manual/en/timezones.php

 


$tz =  new DateTimeZone('Pacific/Nauru');
$date = new DateTime('now', $tz);
echo $date->format('Y-m-d H:i:sP') . "\n";

 

Link to comment
Share on other sites

I didn't realizing linking him to the manual page describing the exact functionality he needs (along with pages upon pages of examples) was a "dungeon master style riddle." Next time someone asks me how to put a nail into a board, I'll give a dissertation on the use of a hammer.  Click the links to the manual pages, read the manual pages, learn something. The last step is important. 

 

As for pointing out the syntax error, he received help and responded to it by simply asking for help.  I gave him additional, nonspecific help to respond to his additional nonspecific request for help.

 

The DateTime class and its related functions are PHP 5.2+ only, and a lot of the timezone functionality is 5.3+.  Since all we had were 3 malformed lines of PHP, assuming he was on PHP 5.3 was too big of a jump for Requinix and me.

 

-Dan

Link to comment
Share on other sites

I didn't realizing linking him to the manual page describing the exact functionality he needs (along with pages upon pages of examples) was a "dungeon master style riddle." Next time someone asks me how to put a nail into a board, I'll give a dissertation on the use of a hammer.  Click the links to the manual pages, read the manual pages, learn something. The last step is important. 

 

As for pointing out the syntax error, he received help and responded to it by simply asking for help.  I gave him additional, nonspecific help to respond to his additional nonspecific request for help.

 

The DateTime class and its related functions are PHP 5.2+ only, and a lot of the timezone functionality is 5.3+.  Since all we had were 3 malformed lines of PHP, assuming he was on PHP 5.3 was too big of a jump for Requinix and me.

 

-Dan

 

Then why don't you *say* that? I understand that some questions are total facepalms because it's like "where do I even begin?" but no one's forcing you to post responses. Additionally, some people aren't adept at paging through manuals describing pages of functionality about concepts they barely understand in the first place. It's nothing but developer pretension. Why not just post "RTFM" ?

Link to comment
Share on other sites

@jim:  Why should we have to explain the reason behind linking someone to the manual?  Don't you think linking someone to the manual implies "You should read this page, I am not linking to it because I'm practicing my linking skills"?

 

@RON: You have been given the solution, twice now.  Debug this on your own, or be more clear as to what "not working" means.  Is the time on the server right?  Do you know what timezone you're in? Have you tried the other two solutions you've been presented with?

Link to comment
Share on other sites

Looking through the manual should be one of the first steps one should take to address a problem they have with the language.  Reading through documentation is something all developers should be comfortable with.  PHP's documentation is some of the best.  It's clear, easy to read, and uses very little jargon.  I don't think it's unreasonable for someone to be directed there as an answer. 

 

Also, while this is a place for people to get help, one shouldn't expect to be spoon fed the answers they are looking for.

 

I found requinix's answer to be more than sufficient.  He provided both functions the OP should use.  Further, the manual pages do an exquisite job describing what the functions do, with relevant examples.  Short of writing the OP's code for him, it was as good an answer as could be expected.

Link to comment
Share on other sites

I'm with jim_keller.

 

This post is nothing though, there are many occasions out there that I see people provide a little attitude with their posts.

 

Look at Nightslyr's recent posts. More 'pointing out where somebody is wrong' rather then helping to solve a problem.

 

But when it's free, you can't really expect any more. I'd personally still rather people not reply though.

Link to comment
Share on other sites

I'm with jim_keller.

 

This post is nothing though, there are many occasions out there that I see people provide a little attitude with their posts.

 

Look at Nightslyr's recent posts. More 'pointing out where somebody is wrong' rather then helping to solve a problem.

 

But when it's free, you can't really expect any more. I'd personally still rather people not reply though.

 

I don't see why pointing out where somebody is wrong can't be part of the learning experience.  I'd much rather receive blunt criticism of my code and design than be strung along by someone who doesn't want to hurt my feelings.  In fact, I have received that kind of treatment here in the past.  It made me a better programmer.  Telling me my code sucks fires up my desire for competition, which spurs me to learn and improve.

 

For me, I personally grow frustrated when I see the following things:

 

1. Someone wanting to be fed the answer.

2. Someone who panics because their code doesn't run correctly the first time.

3. Someone who hasn't attempted to do any troubleshooting on their own.

 

All three tend to indicate a lack of patience or work ethic.  I react far more favorably to those that have demonstrably put forth an honest effort in solving their problems.  It's not 100% accurate, but it's served me well in the vast majority of cases I've encountered.

 

Finally, RTFM is a perfectly reasonable answer in many cases.  In fact, we have a smile for it: :rtfm:  Like I said before, it should be among the first steps someone takes before coming here.*

 

*Yes, yes, there are exceptions.  I try to treat obvious newbies with kid gloves because they often don't know any better.  But someone with a few hundred posts to their credit?  I'm going to have the expectation that they can at least perform basic tasks, like read and follow documentation written at an 8th grade level.

Link to comment
Share on other sites

Nightslyer;

I agree with you. I'm just learning PHP and doing my best to overcome my physical hanicaps.

 

1  - I cant see very well because of a recent tear in mt retna and getting it operated on.

2  - I cannot use my left side,( hands, arm, legs) since having a stroke, so I'm typing now with only one finger. Use to type 110wpm.

3 - I learn better by example. Reading because of my eyesight is somewhat difficult. But I try all the time. So you my think, You need to read on the computer. Yes, but I can enlarge the text so I can read it.

4 - I do this to keep my mind active and to learn. I just learn a little more slowly these days.

 

So what my seem as a easy question to some, isn't to others. I don't post anything here unless I have at least tried to fix it myself. When I become frustrated, then I post and usually it's a missing character or a typo I made.

 

I just posted a question about the if statement. I sure hope someone doesn't think I stupid because it's easy for them!

 

Thanks for your comments....

Bob...

Link to comment
Share on other sites

How can I get the results of CODE B in seconds? I need the result of CODE B to be similar as the result in CODE A. Basically what I need is CODE B to echo in seconds.

 

CODE A

<?php

date_default_timezone_set('Australia/Melbourne');

echo "time=" .time();

?>[/code]

 

CODE B

<?php
$tz =  new DateTimeZone('Australia/Melbourne');
$date = new DateTime('now', $tz);
echo $date->format('Y-m-d H:i:s') . "\n";
?>

 

 

Link to comment
Share on other sites

Nightslyer;

I agree with you. I'm just learning PHP and doing my best to overcome my physical hanicaps.

 

1  - I cant see very well because of a recent tear in mt retna and getting it operated on.

2  - I cannot use my left side,( hands, arm, legs) since having a stroke, so I'm typing now with only one finger. Use to type 110wpm.

3 - I learn better by example. Reading because of my eyesight is somewhat difficult. But I try all the time. So you my think, You need to read on the computer. Yes, but I can enlarge the text so I can read it.

4 - I do this to keep my mind active and to learn. I just learn a little more slowly these days.

 

So what my seem as a easy question to some, isn't to others. I don't post anything here unless I have at least tried to fix it myself. When I become frustrated, then I post and usually it's a missing character or a typo I made.

 

I just posted a question about the if statement. I sure hope someone doesn't think I stupid because it's easy for them!

 

Thanks for your comments....

Bob...

 

Hi Bob, sorry to hear about your physical limitations.  I was born physically disabled myself, so I know some of what you're going through.  The extra hurdles we're faced with make success taste all the sweeter.  I hope you stick with PHP.  It can be very rewarding.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.