java的GreggorianCalendar的小问题

J2EE 码拜 10年前 (2015-04-15) 1307次浏览 0个评论

import java.text.DateFormatSymbols;
import java.util.*;
public class Calendar {

public static void main(String[] args)
{
GregorianCalendar d = new GregorianCalendar();
int today = d.get(Calendar.DAY_OF_MONTH);
int month = d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH,1);
int weekday = d.get(Calendar.DAY_OF_WEEK);
int firstdayofweek = d.getFirstDayOfWeek();
int indents = 0;
do
{
indents++;
d.add(DAY_OF_MONTH, 1);
weekday = d.get(Calendar.DAY_OF_WEEK);
}
while(weekday!=d.getFirstDayOfWeek());

String[] weekdayNAME = new DateFormatSymbols().getShortMonths();
do
{
System.out.printf(“%4s”,weekdayNAME[weekday]);
d.add(Calendar.DAY_OF_MONTH, 1);
weekday = d.get(Calendar.DAY_OF_WEEK);
}
while(weekday!=d.getFirstDayOfWeek());

weekday = d.get(Calendar.DAY_OF_WEEK);

System.out.println();
for(int i = 0;i < indents;i++)
System.out.print(”    “);

d.set(Calendar.DAY_OF_MONTH, 1);
do
{
int day = d.get(Calendar.DAY_OF_MONTH);
System.out.printf(“%3d”,day);
if(day == today)
System.out.print(“*”);
d.add(Calendar.DAY_OF_MONTH, 1);
weekday = d.get(Calendar.DAY_OF_WEEK);
if(weekday == d.getFirstDayOfWeek())
System.out.println();
}
while(month == d.get(Calendar.MONTH));

if(weekday != d.getFirstDayOfWeek()) System.out.println();
}
}
编译时,里面的Calendar.MONTH  Calendar.DAY_OF_MONTH   Calendar.DAY_OFWEEK提示无法解析,用的eclipse

 
java的GreggorianCalendar的小问题
import java.text.DateFormatSymbols;
import java.util.*;
public class Calendar {

public static void main(String[] args)
{
	GregorianCalendar d = new GregorianCalendar();
	int today = d.get(Calendar.DAY_OF_MONTH);
	int month = d.get(Calendar.MONTH);
	d.set(Calendar.DAY_OF_MONTH,1);
	int weekday = d.get(Calendar.DAY_OF_WEEK);
	int firstdayofweek = d.getFirstDayOfWeek();
	int indents = 0;
	do
	{
		indents++;
		d.add(DAY_OF_MONTH, 1);
		weekday = d.get(Calendar.DAY_OF_WEEK);
	}
	while(weekday!=d.getFirstDayOfWeek());

	String[] weekdayNAME = new DateFormatSymbols().getShortMonths();
	do
	{
		System.out.printf("%4s",weekdayNAME[weekday]);
		d.add(Calendar.DAY_OF_MONTH, 1);
		weekday = d.get(Calendar.DAY_OF_WEEK);
	}
	while(weekday!=d.getFirstDayOfWeek());

	weekday = d.get(Calendar.DAY_OF_WEEK);

	System.out.println();
	for(int i = 0;i < indents;i++)
		System.out.print("    ");

	d.set(Calendar.DAY_OF_MONTH, 1);
	do
	{
		int day = d.get(Calendar.DAY_OF_MONTH);
		System.out.printf("%3d",day);
		if(day == today)
			System.out.print("*");
		d.add(Calendar.DAY_OF_MONTH, 1);
		weekday = d.get(Calendar.DAY_OF_WEEK);
		if(weekday == d.getFirstDayOfWeek())
			System.out.println();
	}
	while(month == d.get(Calendar.MONTH));

	if(weekday != d.getFirstDayOfWeek()) System.out.println();
}
}

刚才没发好,重新发一下,这里面的Calendar.DAY_OF_MONTH    Calendar.DAY_OF_WEEK之类的提示无法解析

java的GreggorianCalendar的小问题
10分
import java.util.Calendar;
java的GreggorianCalendar的小问题
30分
你这是自己定义了一个类叫Calendar?  

public class Calendar {

public static void main(String[] args)
{

....

Calendar.DAY_OF_WEEK

然后你自己又用这个类的属性 DAY_OF_WEEK  他这些属性怎么会存在?   java.util.Calendar.DAY_OF_WEEK才行吧?

java的GreggorianCalendar的小问题
太感谢了,这么个小问题啊,刚学java没注意到这个类名的问题,当时就随便定义了个名字,没想到正好冲突了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明java的GreggorianCalendar的小问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!