felito Posted October 23, 2011 Share Posted October 23, 2011 hi this code will output an unique id like: 0.85760300 1319393114 $uniqueId= microtime(); echo $uniqueId; my question is: how can i convert this value to something like: 23/10/2001 19:06 ? thanks Quote Link to comment Share on other sites More sharing options...
xyph Posted October 23, 2011 Share Posted October 23, 2011 mircotime is not a unique ID. <?php list( $ms,$stamp ) = explode( ' ', microtime() ); echo date( 'd/m/Y h:i:s', $stamp ) . ' ' . $ms; ?> Quote Link to comment Share on other sites More sharing options...
felito Posted October 23, 2011 Author Share Posted October 23, 2011 is not an unique id ? I read that is also typically used for unique ID's. This information is wrong ? http://docstore.mik.ua/orelly/webprog/pcook/ch03_14.htm Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 23, 2011 Share Posted October 23, 2011 felito: Is it too hard for you to type in www.php.net/microtime? Maybe you don't realize that the php manual works that way --- you put in the name of the function you want to read about in the url. microtime There is a uniquid function. That function uses microtime to seed a unique id generation algorithm. Also... read the responses to your question. Xyph took the time to reply to you with an example that answered your question about formatting of a time value. Did you read it? If you want an id, then you are going to get something that has the property of uniqueness. It is going to be a string, not a date/time value. Do you want a date/time value or a unique string? Quote Link to comment Share on other sites More sharing options...
xyph Posted October 23, 2011 Share Posted October 23, 2011 PHP implements microtime to help create a pseudo-unique value that has a very low chance of being replicated. Using microtime alone generally isn't enough, as it's predictable. And ideal solution would be to use microtime in combination with things like the users IP and very strong pseudo-random (or random if on a *nix system) data. openssl_random_pseudo_bytes is great, but runs very slow on windows systems and isn't always available to use. Using /dev/random on a *nix system ideal, as it uses environment noise for 'true' random generation. As a worst-case fallback, mt_rand with a combination of the IP and microtime is generally enough, but know mt_rand is considered to be insecure cryptographically. Quote Link to comment Share on other sites More sharing options...
felito Posted October 23, 2011 Author Share Posted October 23, 2011 thanks for your time xyph. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.