码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA日期查询:季度、月份、星期等时间信息

时间:2018-12-09 22:38:30      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:oid   get   public   lse   string   bsp   lan   pre   nbsp   

参考:JAVA日期查询:季度、月份、星期等时间信息

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();;
    }
}

 

JAVA日期查询:季度、月份、星期等时间信息

标签:oid   get   public   lse   string   bsp   lan   pre   nbsp   

原文地址:https://www.cnblogs.com/fitzroy343/p/10093733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!