Используйте объект Date
: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
Объект Date в Javascript работает с миллисекундами, а не секундами, поэтому вам придется умножить метку времени UNIX на 1000:
var myDate = new Date(unix_timestamp * 1000);
Затем вы можете использовать локальный объект Date, чтобы делать все, что вам захочется:
var output = myDate .getHours() + ':';
output += myDate .getMinutes() + ':';
output += myDate .getSeconds();
alert(output);
РЕДАКТИРОВАТЬ Ах, пропустил часть об использовании PST всегда, независимо от локали. unix_timesamp
снова - это отметка времени эпохи / UNIX, которую вы получаете с сервера:
Попробуйте здесь: http://jsfiddle.net/46PYZ/
// set to the UTC offset for the target timezone, PST = UTC - 8
var target_offset = -8;
// create a Date object
var myDate = new Date();
// add local time zone offset to get UTC time in msec
var utc_milliseconds = (unix_timesamp * 1000) + (myDate .getTimezoneOffset() * 60000);
// set the time using the calculated UTC timestamp
myDate.setTime(utc_milliseconds + (3600000 * target_offset));
// now build the yyyy-mm-dd HH:mm format
var output = myDate.getFullYear() + '-';
var month = myDate.getMonth() + 1;
output += (month < 10 ? '0' + month : month) + '-';
output += myDate.getDate() + ' ';
var hours = myDate.getHours() + 1;
output += (hours < 10 ? '0' + hours : hours) + ':';
var minutes= myDate.getMinutes() + 1;
output += (minutes< 10 ? '0' + minutes : minutes);