zoukankan      html  css  js  c++  java
  • 获取当前日期时间,获取当月最后一天

    java获取年 、月、日

    import Java.util.Calendar;

    public class Main {
      public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DATE);
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        int dow = cal.get(Calendar.DAY_OF_WEEK);
        int dom = cal.get(Calendar.DAY_OF_MONTH);
        int doy = cal.get(Calendar.DAY_OF_YEAR);

        System.out.println("Current Date: " + cal.getTime());
        System.out.println("Day: " + day);
        System.out.println("Month: " + month);
        System.out.println("Year: " + year);
        System.out.println("Day of Week: " + dow);
        System.out.println("Day of Month: " + dom);
        System.out.println("Day of Year: " + doy);
      }
    }

    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date currTime = new java.util.Date();

    int year = currTime.getYear();//年

    int month = currTime.getMonth()+1;//月

    int week = currTime.getDay(); //星期几

    int day = currTime.getDate();//日

    String curTime = formatter.format(currTime);

    获取当前日期:

    public class TestDate { 
      public static void main(String[] args) { 
         Date now = new Date(); 
         Calendar cal = Calendar.getInstance();

    }

    获取当月最后一天:

    public static boolean isMonthEnd(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.DATE) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    //求日期天数差
    public static long getCompareDate(String startDate,String endDate) {
    SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
    Date date1 = null,date2 = null;
    try {
    date1 = formatter.parse(startDate);
    date2=formatter.parse(endDate);
    } catch (ParseException e) {
    e.printStackTrace();
    }

    long l = date2.getTime() - date1.getTime();
    long d = l/(24*60*60*1000);
    return d;
    }

  • 相关阅读:
    Android Hal 分析
    Android JNI 使用的数据结构JNINativeMethod详解
    MTK GPIO 一些理解
    DEVICE_ATTR
    DEVICE_ATTR
    内核驱动中常见的miscdevice、platform_device、platform_driver
    DEVICE_ATTR实例分析
    虚拟机安装Ubuntu14.04打开FireFox提示Server not found
    Android编译系统中的Kconfig,Makefile,.config编译系统浅析
    几款在线脑图制作工具
  • 原文地址:https://www.cnblogs.com/chafe/p/6074646.html
Copyright © 2011-2022 走看看