public function format($time, $pattern = 'F', $charset = 'UTF-8')
{
if (is_numeric($time)) {
//assumes unix epoch
$time = floatval($time);
} else {
if (is_string($time)) {
$time = @strtotime($time);
}
}
if ($pattern === null) {
$pattern = 'F';
}
$s = Prado::createComponent('System.Util.TDateTimeStamp');
$date = $s->getDate($time);
$pattern = $this->getPattern($pattern);
$tokens = $this->getTokens($pattern);
for ($i = 0, $k = count($tokens); $i < $k; ++$i) {
$pattern = $tokens[$i];
if ($pattern[0] == "'" && $pattern[strlen($pattern) - 1] == "'") {
$sub = preg_replace('/(^\')|(\'$)/', '', $pattern);
$tokens[$i] = str_replace('``````', '\'', $sub);
} else {
if ($pattern == '``````') {
$tokens[$i] = '\'';
} else {
$function = $this->getFunctionName($pattern);
if ($function != null) {
$fName = 'get' . $function;
if (in_array($fName, $this->methods)) {
$rs = $this->{$fName}($date, $pattern);
$tokens[$i] = $rs;
} else {
throw new Exception('function ' . $function . ' not found.');
}
}
}
}
}
return I18N_toEncoding(implode('', $tokens), $charset);
}