Tuesday, March 6, 2012

how to use server time to make local time

If you are working with php and want's to show time as per your time zone but your server is using php timestamp then you can use  combination of  php and javascript to get your code working for you. Its not easy to make php work with javascript but with little trick you can do it.
<script type="text/javascript"> 
function gettime() { 
var months = new Array(13);
  months[0]  = "Jan";
  months[1]  = "Feb";
  months[2]  = "Mar";
  months[3]  = "Apr";
  months[4]  = "May";
  months[5]  = "Jun";
  months[6]  = "Jul";
  months[7]  = "Aug";
  months[8]  = "Sep";
  months[9]  = "Oct";
  months[10] = "Nov";
  months[11] = "Dec";
var now = new Date(time()*1000); 
var currenthour = now.getHours(); 
var currenttime = now.getMinutes(); 
var currentdate = now.getDate(); 
var monthnumber = now.getMonth();
var monthname=months[monthnumber];
var curYear = now.getFullYear();
curYear=curYear.toString().slice(2);
//var offset = now.gettimezoneOffset(); 
//document.write(now);//.toLocaleString()); 
document.getElementById('curr_time<?php echo $i;?>').innerHTML=currentdate+'-'+monthname+'-'+curYear+' '+currenthour+':'+currenttime;
</script> 
<span id="curr_time<?php echo $i;?>"></span>
<?php 
$time_current = "<script>gettime()</script>";echo $time_current; 
$i++; 

Thursday, March 1, 2012

Do scroll of page to about certain pixel using jquery

You can do page scroll using jquery . Suppose on click event you want to do page scroll upto a certain points. For this use 
$('html,body').animate({scrollTop: $('#xyz').offset().top}, 2000);
give the id from which you want to display.
call it inside a function and call this function ocClick event.