import java.util.Calendar; public class Date { Calendar calendar = null; public void test(){ calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int season; if( month>1 && month<5){ season = 1; } else if( month>4 && month<8 ){ season = 2; } else if( month>7 && month<11 ){ season = 3; } else{ season = 4; } int day = calendar.get(Calendar.DAY_OF_MONTH); int weekday = calendar.get(Calendar.DAY_OF_WEEK); int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); System.out.println( year + "年" + month + "月" + day +"日"); System.out.println(hour + "时" + minute + "分" + second + "秒"); System.out.println(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second); } public static void main(String[] args){ Date d=new Date(); d.test();; } }
原文地址:https://www.cnblogs.com/fitzroy343/p/10093733.html
时间: 2024-10-13 19:58:02