js日期转换Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd

        Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "h+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            //调用
            var date = new Date().Format("yyyy-MM-dd hh:mm:ss");

2:

public class StringToDate {
public static void main(String []args){
    String myString="2011-09-18 11:20:30";
    Date myDate=null;
     DateFormat df = DateFormat.getDateInstance();
    //设置时间格式
     SimpleDateFormat myFormDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    try {
        myDate = df.parse(myString);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
System.out.println(myDate);
}
}

结果:Sun Sep 18 00:00:00 CST 2011

 function Todate(num) {
                //Fri Oct 31 18:00:00 UTC+0800 2008
                num = num + ""; //给字符串后就一个空格
                var date = "";
                var month = new Array();
                month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4;
                month["May"] = 5; month["Jan"] = 6; month["Jul"] = 7; month["Aug"] = 8;
                month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;
                var week = new Array();
                week["Mon"] = "一"; week["Tue"] = "二"; week["Wed"] = "三"; week["Thu"] = "四";
                week["Fri"] = "五"; week["Sat"] = "六"; week["Sun"] = "日";
                str = num.split(" "); //根据空格组成数组
                date = str[5] + "-"; //就是在2008的后面加一个“-”
                //通过修改这里可以得到你想要的格式
                date = date + month[str[1]] + "-" + str[2] + " " + str[3];
                //date=date+" 周"+week[str[0]];
                return date;
            }
时间: 2024-07-30 13:17:55

js日期转换Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd的相关文章

Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd

这个其实网上有很多例子,都是直接用js在前端做了时间处理,我的处理也一样,想要变成2008-3-31,就用下面的js直接可以处理 function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008 num = num + ""; var date = ""; var month = new Array(); month["Jan"] = 1; month["Feb"] = 2;

Oracle中把一个DateTime的字符串转化成date类型。to_date('2016/12/8 18:55:43','yyyy/MM/dd hh24:mi:ss'),

Oracle中把一个DateTime或者该形态字符串转化成date类型. to_date('2016/12/8 18:55:43','yyyy/MM/dd hh24:mi:ss'), 或者: select to_date('2010-10-20 13:23:44','yyyy-mm-dd hh24:mi:ss')  from dual; 是用" /"还是" -"取决于字符串是什么结构的. date类型转换成char类型, 例子to_char(' ','yyyymmd

日期合法性验证(格式为:YYYY-MM-DD或YYYY/MM/DD )

//+---------------------------------------------------  //| 日期合法性验证  //| 格式为:YYYY-MM-DD或YYYY/MM/DD  //+---------------------------------------------------  function IsValidDate(DateStr)   {       var sDate=DateStr.replace(/(^\s+|\s+$)/g,''); //去两边空格;

字符串转成日期类型(格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd)

//+---------------------------------------------------  //| 字符串转成日期类型   //| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd  //+---------------------------------------------------  function StringToDate(DateStr)  {         var converted = Date.parse(D

js日期转换工具

var dq = new Date();//定义当前时间var sDueDate = formatDate(dq);/调用日期转换方法 传入当前时间 //进行日期转换 function formatDate(now) { debugger var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate()-10; var hour = now.getHours(); var minute =

js日期转换和格式化

1.日期格式化 Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "H+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getS

js日期转换

1. 获取当前日期(2015-05-05) function toDate(){ var myDate = new Date(); var years = myDate.getFullYear(); var months = myDate.getMonth() + 1; var days = myDate.getDate(); var clock = years +"-"; if(months < 10) { clock +="0"; } clock += m

moment.js 日期转换工具

官方网站: http://momentjs.cn/ 文档: https://itbilu.com/nodejs/npm/4Jxk-Ti-l.html https://www.jianshu.com/p/5715f4bad95c 原文地址:https://www.cnblogs.com/echolife/p/11751397.html

这里有个坑---js日期格式yyyy-MM-dd与yyyy/MM/dd

这里有个坑,---------每一个遇到的坑总结后都是一比财富. 我们写脚本的时候,一般定义一个日期格式会使用“2015-12-21”和“2015/12/21”两种数据格式,由于各取所需日期格式并没有优劣可分.但是当我们使用如下语句转换日期格式的时候请注意以下问题. 1.var dtNow=new Date('2015-12-21'); 2.var dtNow=new Date('2015/12/21'); 当我们在chorme浏览器上使用的时候会发现两种方法都是可以准确的转换为所需日期格式的.