js时间戳转换为可读格式..需要复制php功能


js timestamp to readable format... need to replicate php function

我遇到了一个独特的情况,即我不能再使用php来格式化时间戳,而是需要使用jquery/js。

php中的:

给定("2014-04-01 20:05:00","FjS,Y@g:i a")将返回"2014年4月1日晚上8:05"

// Date/time converter for strings
function convertStringTime($timestamp, $format)
{
    if ($timestamp == '' or $timestamp == 0)
    {
        return 'n/a';
    }
    else // return actual time
    {
        $timestamp = strtotime($timestamp);
        $timestamp = date($format, $timestamp);
        return $timestamp;
    }
}

我需要用相同的输入和输出在jquery/js中复制这个函数。我做了一些快速搜索,但找不到任何类型的内置调用来格式化日期/时间。真的没有提供任何东西来做这件事吗?

jQuery dateFormat是一个独立的插件。您需要使用<script>标记显式地加载它。直接你没有任何选择。