Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript将日期和时间转换为特定格式_Javascript_Date_Datetime_Type Conversion - Fatal编程技术网

javascript将日期和时间转换为特定格式

javascript将日期和时间转换为特定格式,javascript,date,datetime,type-conversion,Javascript,Date,Datetime,Type Conversion,我是一名新手,想将2014-09-25T09:54:00转换为9:54 am,9月25日周四 有人能给我推荐一种用javascript实现的方法吗 谢谢正如Phrogz所说: 进入JavaScriptDate对象 不管你喜欢什么东西都可以 另见:和问题 例如: var myDate=新日期(“2014-09-25T09:54:00”) var myString=myDate.customFormat(“#h#:#mm#AMPM##DDD#,#D#th#MMM#”); 请参阅此代码的实际操作我为

我是一名新手,想将
2014-09-25T09:54:00
转换为
9:54 am,9月25日周四

有人能给我推荐一种用javascript实现的方法吗

谢谢

正如Phrogz所说:

  • 进入JavaScript
    Date
    对象
  • 不管你喜欢什么东西都可以
  • 另见:和问题

    例如:

    var myDate=新日期(“2014-09-25T09:54:00”)
    var myString=myDate.customFormat(“#h#:#mm#AMPM##DDD#,#D#th#MMM#”);
    
    请参阅此代码的实际操作

    我为您的案例制作了一个示例

    它是基于这个很棒的教程,使格式化日期非常容易

    Javascript代码:
    var d_name=新数组(“Sun”、“Mon”、“Tue”,
    “星期三”、“星期四”、“星期五”、“星期六”);
    var m_name=新数组(“一月”、“二月”、“三月”,
    “四月”、“五月”、“六月”、“七月”、“八月”、“九月”,
    “十月”、“十一月”、“十二月”);
    var d=新日期();
    var curr_date=d.getDate();
    var sup=“”;
    如果(当前日期==1 | |当前日期==21 | |当前日期==31)
    {
    sup=“st”;
    }
    否则如果(当前日期==2 |当前日期==22)
    {
    sup=“nd”;
    }
    否则如果(当前日期==3 |当前日期==23)
    {
    sup=“rd”;
    }
    其他的
    {
    sup=“th”;
    }
    var a_p=“”;
    var curr_hour=d.getHours();
    如果(当前小时<12)
    {
    a_p=“AM”;
    }
    其他的
    {
    a_p=“PM”;
    }
    如果(当前小时==0)
    {
    当前小时=12;
    }
    如果(当前小时数>12)
    {
    当前小时=当前小时-12;
    }
    var curr_day=d.getDay();
    var curr_min=d.getMinutes();
    var curr_month=d.getMonth();
    var curr_year=d.getFullYear();
    var curr_hour=d.getHours();
    警报((当前时间+):“+curr\u min+”“+a\u p)+”(“+d\u名称[当前日期]+”,“+curr\u日期+sup+”)
    +货币单位名称[货币单位月份]/*+“”+货币单位年份*/)请检查
    
    here is a great JavaScript library that handles this very well, and only 5.5kb minified.
    
    http://momentjs.com/
    
    It looks something like this:
    
    
    moment().format('MMMM Do YYYY, h:mm:ss a'); // February 25th 2013, 9:54:04 am
    moment().subtract('days', 6).calendar(); // "last Tuesday at 9:53 AM"
    You can also pass in dates as a String with a format, or a Date object.
    
    var date = new Date();
    moment(date); // same as calling moment() with no args
    
    // Passing in a string date
    moment("12-25-1995", "MM-DD-YYYY");
    Also has great support for languages other then English, like, Russian, Japanese, Arabic, Spanish, etc..