〈%=month(js date month())%〉的结果

博客分类:
java.util.Date
-----------
date.getTime()返回的是什么?
问题:
-------------
Date date = new Date();
System.out.println(date.getTime());
输出结果是5
编译时间当时时间大概是好14.16分
谁能给我解释下这数字分别是什么意思?
答案:
-------------
你想得到时间格式为这种吧?
date.getTime()所返回的是一个long型的毫秒数
获取特定格式的时间需要格式化的。
例子:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.format(new Date());
得到的日期格式为:
------------------------
扩展:date()的方法
1、獲取服務器端當前日期:
&%@ page import="java.util.Date"%&
Date myDate = new Date();
%&
2、獲取當前年、月、日、星期:
&%@ page import="java.util.Date"%&
Date myDate = new Date();
int thisYear = myDate.getYear() + 1900;//thisYear = 2003
int thisMonth = myDate.getMonth() + 1;//thisMonth = 5
int thisDate = myDate.getDate();//thisDate = 30
int thisDay = myDate.getDay();//thisDay = 1
%&
3、按本地時區輸出當前日期
&%@ page import="java.util.Date"%&
Date myDate = new Date();
out.println(myDate.toLocaleString());
%&
輸出結果為:
4、獲取數據庫中字段名為"publish_time"、類型為Datetime的值
&%@ page import="java.util.Date"%&
...連接數據庫...
ResultSet rs = ...
Date sDate = rs.getDate("publish_time");
%&
5、按照指定格式打印日期
&%@ page import="java.util.Date"%&
&%@ page import="java.text.DateFormat"%&
Date dNow = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
out.println("It is " + formatter.format(dNow));
%&
輸出的結果為:
It is 星期五
at 11:30:46 上午 CST
(更為詳盡的格式符號請參看SimpleDateFormat類)
6、將字符串轉換為日期
&%@ page import="java.util.Date"%&
&%@ page import="java.text.DateFormat"%&
String input = "";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
t = formatter.parse(input);
out.println(t);
}catch(ParseException e){
out.println("unparseable using" + formatter);
%&
輸出結果為:Fri Nov 11 00:00:00 CST 1222
7、計算日期之間的間隔
&%@ page import="java.util.Date"%&
&%@ page import="java.text.DateFormat"%&
String input = "";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
trycatch(ParseException e)
Date d2 = new Date();
long diff = d2.getTime() - d1.getTime();
out.println("Difference is " + (diff/(*24)) + " days.");
%&
輸出結果為:
Difference is 29 days.
8、日期的加減運算
方法:用Calendar類的add()方法
&%@ page import="java.util.*"%&
&%@ page import="java.text.*"%&
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
out.println("It is now " + formatter.format(now.getTime()));
now.add(Calendar.DAY_OF_YEAR,-(365*2));
out.println("&br&");
out.println("Two years ago was " + formatter.format(now.getTime()));
%&
輸出結果為:
It is now 星期五
at 01:45:32 下午 CST
Two years ago was 星期三
at 01:45:32 下午 CST
9、比較日期
方法:用equals()、before()、after()方法
&%@ page import="java.util.*"%&
&%@ page import="java.text.*"%&
DateFormat df = new SimpleDateFormat("yyy-MM-dd");
Date d1 = df.parse("");
Date d2 = df.parse("");
String relation =
if(d1.equals(d2))
relation = "the same date as";
else if(d1.before(d2))
relation = "before";
relation = "after";
out.println(d1 +" is " + relation + ' ' + d2);
%&
輸出結果為:
Sat Jan 01 00:00:00 CST 2000 is after Fri Dec 31 00:00:00 CST 1999
10、記錄一件事所花費的時間
方法:調用兩次System.getTimeMillis()方法,求差值
&%@ page import="java.text.*"%&
long t0,t1;
t0 = System.currentTimeMillis();
out.println("Cyc starts at " + t0);
int k = 0;
for(int i =0;i&100000;i++)
t1 = System.currentTimeMillis();
out.println("&br&");
out.println("Cyc ends at " + t1);
out.println("&br&");
out.println("This run took " + (t1-t0) + "ms.");
%&
輸出結果為:
Cyc starts at 2
Cyc ends at 2
This run took 10ms.
11、其它:如何格式化小數
&%@ page import="java.text.*"%&
DecimalFormat df = new DecimalFormat(",###.00");
double aNumber = .6568975;
String result = df.format(aNumber);
out.println(result);
%&
輸出結果為:
33,665,448,856.66
浏览 67347
浏览: 465683 次
不错,支持很好
谢谢您能将知识精华汇编总结,让初学者们从原理中学会和提高。
谢谢了,顶顶
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'&>&定义一个Date 类,数据成员有year,month, day。以“年_月_日“的格式输出日期, 还提供把天加一的成员函数nextdate( ),要求能测试出如下的结果:
定义一个Date 类,数据成员有year,month, day。以“年_月_日“的格式输出日期, 还提供把天加一的成员函数nextdate( ),要求能测试出如下的结果:
上传大小:1000B
定义一个Date 类,数据成员有year,month, day。以“年_月_日“的格式输出日期, 还提供把天加一的成员函数nextdate( ),要求能测试出如下的结果:
a. 能够进入下一个月。
b. 能够进入下一个年。
c. 能显示日期。
综合评分:5
下载个数:
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有2条
中规中矩的,不错
还不错的,很实用
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
定义一个Date 类,数据成员有year,month, day。以“年_月_日“的格式输出日期, 还提供把天加一的成员函数nextdate( ),要求能测试出如下的结果:
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
fhxtianxia
举报的资源分:
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*详细原因:
定义一个Date 类,数据成员有year,month, day。以“年_月_日“的格式输出日期, 还提供把天加一的成员函数nextdate( ),要求能测试出如下的结果:JavaScript基础教程 列表
JavaScript Date getMonth 方法:取得表示月份的数字JavaScript Date getMonth 方法
getMonth 方法用于取得 Date 对象中表示月份的数字。语法如下:
date_obj.getMonth()
该方法总是结合一个 Date 对象来使用。
得到 0-11 的数字表示 1-12 月份。
getMonth 方法实例
该例子从当前的时间中取得月份数字:
&script language=&JavaScript&&
var d = new Date();
document.write( d.getMonth() );
运行该例子,输出:
注意:实际的月份是 4 月。
该例子正确的输出自定义的月份:
&script language=&JavaScript&&
var d = new Date();
month_array = new Array('一','二','三','四','五','六','七','八','九','十','十一','十二');
document.write( month_array[d.getMonth()] + '月' );
运行该例子,输出:
本章节内容共分 18 部分:1.
JavaScript Date getMonth 方法:取得表示月份的数字4.
5idev.com(我爱开发网) — 提供最好的 、、、 及to month to date
月初到现在
本月至今累计
本月到今天为止
当前月累计销售
年与月累计字段
更多收起网络短语
The widget includes convenient controls for frequently used time windows such as one week, one month, month to date, year to date and more.
该小部件包括对频繁使用的时间窗口(如一周、一个月、月初到当日和年初到当日等)的方便控制。
This class supports changing the date by different settings via constants in the Calendar class; for example, Calendar.WEEK_OF_MONTH to change the date one week at a time.
该类支持通过将 Calendar 类中的常数设置为不同的值来更改日期;例如, Calendar.WEEK_OF_MONTH 每次将日期更改一周。
Better news on the economy, particularly manufacturing, set off a rally early in the month that still has the Dow Jones industrial average up 5.1 percent for the month to date.
经济方面的利好消息,尤其是制造业的新闻,推动9月初美国股市上扬,道琼斯工业平均指数当月上涨5.1%。
"In case you haven't seen a sales report these days, February MTD sales are a total disaster, " Jerry Murray, Wal-Mart's vice president of finance and logistics, wrote in a 12 February email to other executives, referring to month-to-date sales.
This additional borrowing authority would give Treasury the capacity to issue enough new debt to stave off the default date for another month or two, according to calculations by the Bipartisan Policy Center think tank in Washington.
Shares of Boeing stock fell just 1.17% on Monday, and are down only 1.59% for the month to date.
$firstVoiceSent
- 来自原声例句
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!博主最新文章
博主热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 js date getmonth 的文章

 

随机推荐