Calendar问题,50分,希望高手们多多探讨 Date now=new Date();SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");System.out.println(formatter.format(now)); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to tomtian(老猫):这种方法我知道,但是我主要想搞清Calendar //********************************************* //功 能: //参 数: //返回值: //********************************************* public static String getTime() { String strTime = ""; cal = new GregorianCalendar(); nYear = cal.get(Calendar.YEAR); nMonth = cal.get(Calendar.MONTH); nDate = cal.get(Calendar.DAY_OF_MONTH); nHour = cal.get(Calendar.HOUR); nMin = cal.get(Calendar.MINUTE); nSec = cal.get(Calendar.SECOND); strTime += nYear; if (nMonth < 10) { strTime += "-0"; } else { strTime += "-"; } nMonth++; strTime += nMonth; if (nDate < 10) { strTime += "-0"; } else { strTime += "-"; } strTime += nDate; if (nHour < 10) { strTime += " 0"; } else { strTime += " "; } strTime += nHour; if (nMin < 10) { strTime += ":0"; } else { strTime += ":"; } strTime += nMin; if (nSec < 10) { strTime += ":0"; } else { strTime += ":"; } strTime += nSec; return strTime; } private static Calendar cal = null; private static int nYear = 0; private static int nMonth = 0; private static int nDate = 0; private static int nHour = 0; private static int nMin = 0; private static int nSec = 0; System.out.println(formatter.format(cal.toTime())); 你可以直接看到它的源码,Calendar是个抽象类,YEAR是一个final的变量默认的getInstance调用 new GeorageCalendar() System.out.pritnln(Calendar.YEAR+"-"+Calendar.MONTH+"-"+Calendar.DATE);老兄,Calendar.YEAR 只是一个常量 ,它永远都是1 .同样Calendar.MONTH 代表的是2,Calendar.DATE代表的是5 .它们是一个常量就像你自己定义一个 int ABCD = 5 一样这里的ABCD 就是 Calendar.YEAR .它只是一个名字,不是 Calendar.getYear() !!!!! 同意楼上的意见,但有个小小的问题Calendar类有getYear()方法马??这样就行了Calendar calendar = Calendar.getInstance();System.out.print(calendar.get(Calendar.MONTH)+1); 请教一个题目,请大家帮忙解决下!谢谢 求助!一个java编程 请教关于学习方向的问题 表格操作问题,大虾指点!急等!! 关于数组中相同元素相加 字符串相加de编码问题 java中有没有类似delphi中dbgrid控件,用于显示数据库内容的控件????????????????????? 怎么取得一个数据值在内存中占的大小? 看过《THINK IN JAVA》 的朋友请进来 小弟最近要开发图像矢量化课题(java开发),有谁能推荐关于这方面的算法和java书? 如何从string中提取自己需要的一部分字符 请帮我看看这个变量(属性)属于什么类型,谢谢!
//功 能:
//参 数:
//返回值:
//*********************************************
public static String getTime()
{
String strTime = "";
cal = new GregorianCalendar();
nYear = cal.get(Calendar.YEAR);
nMonth = cal.get(Calendar.MONTH);
nDate = cal.get(Calendar.DAY_OF_MONTH);
nHour = cal.get(Calendar.HOUR);
nMin = cal.get(Calendar.MINUTE);
nSec = cal.get(Calendar.SECOND); strTime += nYear;
if (nMonth < 10)
{
strTime += "-0";
}
else
{
strTime += "-";
}
nMonth++;
strTime += nMonth; if (nDate < 10)
{
strTime += "-0";
}
else
{
strTime += "-";
}
strTime += nDate; if (nHour < 10)
{
strTime += " 0";
}
else
{
strTime += " ";
}
strTime += nHour; if (nMin < 10)
{
strTime += ":0";
}
else
{
strTime += ":";
}
strTime += nMin; if (nSec < 10)
{
strTime += ":0";
}
else
{
strTime += ":";
}
strTime += nSec;
return strTime; }
private static Calendar cal = null; private static int nYear = 0;
private static int nMonth = 0;
private static int nDate = 0;
private static int nHour = 0;
private static int nMin = 0;
private static int nSec = 0;
默认的getInstance调用 new GeorageCalendar()
Calendar.DATE代表的是5 .它们是一个常量就像你自己定义一个 int ABCD = 5 一样
这里的ABCD 就是 Calendar.YEAR .它只是一个名字,不是 Calendar.getYear() !!!!!
这样就行了
Calendar calendar = Calendar.getInstance();
System.out.print(calendar.get(Calendar.MONTH)+1);