zoukankan      html  css  js  c++  java
  • simpleDateFormat 格式时间方法运用

    package day27work;

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Scanner;

    public class work2 {

        public static void main(String[] args) throws ParseException {
            // TODO Auto-generated method stub
           life();
           //runnian();
        }
        //闰年的计算
        public static void runnian() throws ParseException {
            SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd");
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入年份");
            int i=sc.nextInt();
            Date date1=time.parse(i+"-2-1");
            long ss=date1.getTime();
            System.out.println(ss);
            
            Date date2=time.parse(i+"-3-1");
            long ss1=date2.getTime();
            System.out.println(ss1);
            long ss3=ss1-ss;
            long day=(ss3/1000/3600/24);
            System.out.println(day);
            if(day==29) {
                System.out.println(i+"年是闰年");
            }else if(day==28) {
                System.out.println(i+"年是平年");
            }
        }
        //自己活了多少天
        public static void life() throws ParseException {
            //StringBuffer buffer=new StringBuffer();
            Date date=new Date();
            //System.out.println(date);
            long time1=date.getTime();
            System.out.println(time1);
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入你的出生日期:格式为 年-月-日");
            String life=sc.next();//键盘输入字符样式
            Date date2=sdf.parse(life);
            long time2=date2.getTime();
            System.out.println(time2);
            long time3=time1-time2;
            long day=time3/1000/3600/24;
            System.out.println(day+"天");
        }
    }

  • 相关阅读:
    python 全局变量与局部变量
    Python 百分号字符串拼接
    Python集合的基本操作
    sorted by value in dict python
    gVim vundle
    vim config
    vim move the cursor in a long sentence
    步步为营-37-自动生成数据库连接字符串
    步步为营-36-ADO.Net简介
    步步为营-35-SQL语言基础
  • 原文地址:https://www.cnblogs.com/fbbg/p/10561889.html
Copyright © 2011-2022 走看看