unemployment Posted June 6, 2011 Share Posted June 6, 2011 I am using a mysql db and I use this time function as a parameter in my news feed. I want a JavaScript equivalent so that I can pull in the data via Ajax. Any idea what that would be? echo $now = date('Y-m-d H:s:i', time()); Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/ Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 This tizag link will show you all you need to now I think: http://www.tizag.com/javascriptT/javascriptdate.php Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225929 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 this will help Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225931 Share on other sites More sharing options...
unemployment Posted June 6, 2011 Author Share Posted June 6, 2011 this will help URL, please? Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225933 Share on other sites More sharing options...
unemployment Posted June 6, 2011 Author Share Posted June 6, 2011 This tizag link will show you all you need to now I think: http://www.tizag.com/javascriptT/javascriptdate.php Unfortunately it didn't even though I tried creating a function for it. Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225934 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 oops im sorry. here Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225937 Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 Something like this? (I didn't verfiy this) var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() currentDate = year + "-" + month + "-" + day if (minutes < 10){ minutes = "0" + minutes } thetime = hours + ":" + minutes + " " if (hours > 11) { ampm = "PM" } else { ampm = "AM" } fulldatetime = currentDate + " " + thetime + " " ampm Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225941 Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 The code above works but you'll need to fix the syntax error at the end: fulldatetime = currentDate + " " + thetime + " " ampm TO fulldatetime = currentDate + " " + thetime + " " + ampm Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225956 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 If you're using AJAX, then I'm assuming you're connecting to a PHP script. Why not just have PHP generate the date from there? Or if you want the date to be selectable / relative to the client-time, then you could pass in a unix timestamp (which is much easier to generate with JS) and again let PHP handle the formatting. Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225966 Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 I agree. I would always use PHP instead of javascript if possible. Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225969 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 I agree. I would always use PHP instead of javascript if possible. both have there pros and cons Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225977 Share on other sites More sharing options...
Maq Posted June 6, 2011 Share Posted June 6, 2011 I agree. I would always use PHP instead of javascript if possible. both have there pros and cons Care to elaborate? Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225993 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 I agree. I would always use PHP instead of javascript if possible. both have there pros and cons Care to elaborate? well its a situational kind of thing...it depends what you need to be done to declare which language would be better suited for you...i wouldnt go as far as saying that I would always use PHP instead of js... Quote Link to comment https://forums.phpfreaks.com/topic/238561-php-to-javascript-equivalent/#findComment-1225996 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.