
1,Date date = new Date();
Systemoutprintln(datetoLocaleString());
2,以上程序是使用上述格式打印出当前的日期。
3,以下是根据上述格式的字符串构造出一个date对象供程序使用
public static Date constructDate(String time){
boolean result = Patternmatches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}", time);
if(!result)
return null;
String ymd = timesplit(" ")[0];
String hms = timesplit(" ")[1];
String[] ymds = ymdsplit("-");
String[] hmss = hmssplit(":");
return new Date(IntegerparseInt(ymds[0])-1900,IntegerparseInt(ymds[1])-1,IntegerparseInt(ymds[2]),
IntegerparseInt(hmss[0]),IntegerparseInt(hmss[1]),IntegerparseInt(hmss[2]));
}
时间戳改时间,简单点 alert((new Date("1412849746"))toLocaleDateString())
datesetDate(dategetDate() + 60);//这里的60就是你要加的天数,减也可以。年、月会相应加上去,值得注意的是dategetMonth()得到的月份比实际月份小1,所以实际月份是(dategetMonth()+1)
它的getMilliSeconds也是获取当前时间的毫秒数。所以我们需要自己做一个转换。 可以用getMinutes和getSeconds先获取到相应的分和秒,然后将分601000+秒 1000即可转换了。
应为要有交互,选择了Js来实现,也算是
结对编程
的初试吧。
我将显示部分用html
写好,点击的按钮触发事件函数是check();
复制代码
代码如下:
function
onCheck(){
var
Year
=
documentgetElementById("year")value;
//获取文本框的“年”
var
theYear
=Year
1;
//转换为number类型
//alert(theYear);
//
获取月值
var
month
=
documentgetElementById("month");
var
index1=monthselectedIndex;
var
theMonth
=
monthoptions[index1]value;
//获取月值
var
day
=
documentgetElementById("day");
var
index2=dayselectedIndex;
var
theDay
=
dayoptions[index2]value;
//
输入值判断部分
//调用核心函数
days(theYear,theMonth,theDay);
}
以上就是关于JS 取得当前日期格式为 xxxx-xx-xx全部的内容,包括:JS 取得当前日期格式为 xxxx-xx-xx、js如何获得系统时间年月日时分秒、js实现日历可获得指定日期周数及星期几示例分享(js获取星期几)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)