www.webdeveloper.com
Results 1 to 3 of 3

Thread: URGENT : PHP DateFormat

  1. #1
    Join Date
    Mar 2012
    Posts
    63

    Unhappy URGENT : PHP DateFormat

    Dear All,

    i am using following calendar,

    http://code.google.com/p/jquery-even...2.zip&can=2&q=

    for my work,

    In this they used date value as "1356877050000" for JSON parser to get the date of 30th DEC 2012 19:47


    i checked with some other blogs, this value (1356877050000) forms from microtime , but i don;t know by which format of date they getting this value

    Another key :

    echo '[';
    $separator = "";
    $days = 16;
    echo ' { "date": "1314579600000", "type": "meeting", "title": "Test Last Year", "description": "Lorem Ipsum dolor set", "url": "http://www.event3.com/" },';
    echo ' { "date": "1377738000000", "type": "meeting", "title": "Test Next Year", "description": "Lorem Ipsum dolor set", "url": "http://www.event3.com/" },';
    for ($i = 1 ; $i < $days; $i= 1 + $i * 2) {
    echo $separator;
    $initTime = (intval(microtime(true))*1000) + (86400000 * ($i-($days/2)));
    echo ' { "date": "'; echo $initTime; echo '", "type": "meeting", "title": "Project '; echo $i; echo ' meeting", "description": "Lorem Ipsum dolor set", "url": "http://www.event1.com/" },';
    }

    From this any Key ? its making 24 hrs to find out )

    Thanks
    masterwin

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    969
    While it's hard to be sure of this since I have no information about the timezone those timestamps were generated in, it would appear these values are simply a unix timestamp converted to milliseconds. So this simply means you need to divide the value by 1000 to convert it back to a normal unix timestamp and from there getting a date value is simple in PHP.
    PHP Code:
    $exampleTime 1356877050000;
    $exampleUnix $exampleTime 1000;
    echo 
    date("d M Y H:i"$exampleUnix); 
    Assuming the timestamp was generated in GMT+6(give or take 1) then this would be correct.

    I should also mention that just based on the additional code you gave, that method would probably not apply to every single value you would have. It appears that the loop running in that code is not only converting the timestamp to milliseconds but it is adding (or in some cases subtracting) a number of time from the value using
    Code:
     + (86400000 * ($i-($days/2)));
    but since all of this code is out of context and I don't really feel like downloading and digging through a bunch of code I'm never going to use, I'll just say stick with the first part of my post. If it seems to properly convert all of your values then no worries. If it still gives you some incorrect dates you'll have to dig a bit deeper and resolve the issue of when or why the timestamps are being modified.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Mar 2012
    Posts
    63

    Cool

    Quote Originally Posted by Sup3rkirby View Post
    While it's hard to be sure of this since I have no information about the timezone those timestamps were generated in, it would appear these values are simply a unix timestamp converted to milliseconds. So this simply means you need to divide the value by 1000 to convert it back to a normal unix timestamp and from there getting a date value is simple in PHP.
    PHP Code:
    $exampleTime 1356877050000;
    $exampleUnix $exampleTime 1000;
    echo 
    date("d M Y H:i"$exampleUnix); 
    Assuming the timestamp was generated in GMT+6(give or take 1) then this would be correct.

    I should also mention that just based on the additional code you gave, that method would probably not apply to every single value you would have. It appears that the loop running in that code is not only converting the timestamp to milliseconds but it is adding (or in some cases subtracting) a number of time from the value using
    Code:
     + (86400000 * ($i-($days/2)));
    but since all of this code is out of context and I don't really feel like downloading and digging through a bunch of code I'm never going to use, I'll just say stick with the first part of my post. If it seems to properly convert all of your values then no worries. If it still gives you some incorrect dates you'll have to dig a bit deeper and resolve the issue of when or why the timestamps are being modified.

    @ Sup3rkirby ,

    Really a big thanks for your reply,

    echo strtotime('2013-01-13 06:00');

    so far, this is time 6 AM, the calendar shows event be at 11.30 ( like +5.30 ) ( this is my timezone india GMT+5.30)

    Really big thanks , i wil give friend request here, please accept it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles