本人初学Java,哪位大神帮忙看一看,我这个错在哪里?
packagecn.bjsxtVisualCalendar;importjava.text.DateFormat;importjava.text.DateFormatSy...
package cn.bjsxtVisualCalendar;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.Format;
public class VisualCalendar {
public static void main(String[] args) {
String temp = "2015-10-10";
DateFormat df2=new SimpleDateFormat("YYYY-MM-DD");
try{
Date d2 =df2.parse(temp);
Calendar calendar=new GregorianCalendar();
calendar.setTime(d2);
calendar.set(Calendar.DATE, 1);
System.out.println(Calendar.get(Calendar.DAY_OF_WEEK));
Date date1=Calendar.get(Calendar.DAY_OF_WEEK);
System.out.println(Calendar.getActualMaximum(Calendar.DATE));
int h= Calendar.getActualMaximum(Calendar.DATE);
System.out.print("日\t一\t二\t三\t四\t五\t六");
System.out.println();
for (int i = 1; i <= h; i++) {
System.out.print(i + "\t");
j++;
if (date1==Calendar.SATURDAY) {
System.out.println();
}
Calendar.add(Calendar.DATE,1);
}
}catch(ParseException e){
e.printStackTrace();
}
}
}
不知道怎么改。。 展开
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.Format;
public class VisualCalendar {
public static void main(String[] args) {
String temp = "2015-10-10";
DateFormat df2=new SimpleDateFormat("YYYY-MM-DD");
try{
Date d2 =df2.parse(temp);
Calendar calendar=new GregorianCalendar();
calendar.setTime(d2);
calendar.set(Calendar.DATE, 1);
System.out.println(Calendar.get(Calendar.DAY_OF_WEEK));
Date date1=Calendar.get(Calendar.DAY_OF_WEEK);
System.out.println(Calendar.getActualMaximum(Calendar.DATE));
int h= Calendar.getActualMaximum(Calendar.DATE);
System.out.print("日\t一\t二\t三\t四\t五\t六");
System.out.println();
for (int i = 1; i <= h; i++) {
System.out.print(i + "\t");
j++;
if (date1==Calendar.SATURDAY) {
System.out.println();
}
Calendar.add(Calendar.DATE,1);
}
}catch(ParseException e){
e.printStackTrace();
}
}
}
不知道怎么改。。 展开
3个回答
展开全部
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class VisualCalendar
{
public static void main(String[] args) throws ParseException
{
String temp = "2015-10-10";
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date d2 = df2.parse(temp);
Calendar calendar = Calendar.getInstance();
calendar.setTime(d2);
// 这个月的1号是星期几
calendar.set(Calendar.DATE, 1);
int day = calendar.get(Calendar.DAY_OF_WEEK);
int start = Calendar.SUNDAY;
calendar.add(Calendar.DATE, -day + start);
System.out.println("日\t一\t二\t三\t四\t五\t六");
while(start < day)
{
System.out.print(calendar.get(Calendar.DATE) + "\t");
calendar.add(Calendar.DATE, 1);
start++;
}
calendar.setTime(d2);
calendar.set(Calendar.DATE, 1);
Date now = calendar.getTime();
calendar.add(Calendar.MONTH, 1);
Date next = calendar.getTime();
for(Date cur = now; cur.before(next);)
{
calendar.setTime(cur);
System.out.print(calendar.get(Calendar.DATE) + "\t");
if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
{
System.out.println();
}
calendar.add(Calendar.DATE, 1);
cur = calendar.getTime();
}
calendar.add(Calendar.DATE, -1);
int to = calendar.get(Calendar.DAY_OF_WEEK);
int end = Calendar.SATURDAY;
while(to < end)
{
calendar.add(Calendar.DATE, 1);
System.out.print(calendar.get(Calendar.DATE) + "\t");
to++;
}
System.out.println();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-10-10
展开全部
不知道你从哪里扒的代码,错误一大堆.下面的是改好的,除了 package cn.bjsxtVisualCalendar;这句话其它的都换掉吧,类名换成你的
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;
/**
* Created by yangguangyue on 15/10/9.
*/
public class VisualCalendar {
public static void main(String[] strs){
String temp = "2015-10-10";
SimpleDateFormat df2=new SimpleDateFormat("YYYY-MM-DD");
try{
Date d2 =df2.parse(temp);
Calendar calendar=new GregorianCalendar();
calendar.setTime(d2);
calendar.set(DATE, 1);
System.out.println(calendar.get(DAY_OF_WEEK));
int date1=calendar.get(DAY_OF_WEEK);
System.out.println(calendar.getActualMaximum(DATE));
int h= calendar.getActualMaximum(DATE);
System.out.print("日\t一\t二\t三\t四\t五\t六");
System.out.println();
for (int i = 1; i <= h; i++) {
System.out.print(i + "\t");
// j++;
if (date1== SATURDAY) {
System.out.println();
}
calendar.add(DATE,1);
}
}catch(ParseException e){
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;
/**
* Created by yangguangyue on 15/10/9.
*/
public class VisualCalendar {
public static void main(String[] strs){
String temp = "2015-10-10";
SimpleDateFormat df2=new SimpleDateFormat("YYYY-MM-DD");
try{
Date d2 =df2.parse(temp);
Calendar calendar=new GregorianCalendar();
calendar.setTime(d2);
calendar.set(DATE, 1);
System.out.println(calendar.get(DAY_OF_WEEK));
int date1=calendar.get(DAY_OF_WEEK);
System.out.println(calendar.getActualMaximum(DATE));
int h= calendar.getActualMaximum(DATE);
System.out.print("日\t一\t二\t三\t四\t五\t六");
System.out.println();
for (int i = 1; i <= h; i++) {
System.out.print(i + "\t");
// j++;
if (date1== SATURDAY) {
System.out.println();
}
calendar.add(DATE,1);
}
}catch(ParseException e){
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询