当前位置: 首页 > news >正文

浦东新区苏州网站建设全网营销系统是不是传销

浦东新区苏州网站建设,全网营销系统是不是传销,企业邮箱 网站建设,网页编辑简单分为网页美工编辑和目录 什么是Calendar 类 Calendar日期获取,设置,加减 LocalDateTime日期获取,设置,加减 LocalDateTime日期时间的加减 当前时间基础上,指定本年当中的第几天 获取日期的年月日周时分秒 时间日期前后的比较与判断…

目录

什么是Calendar 类

Calendar日期获取,设置,加减

LocalDateTime日期获取,设置,加减

LocalDateTime日期时间的加减

当前时间基础上,指定本年当中的第几天

获取日期的年月日周时分秒

 时间日期前后的比较与判断

类型转换时间戳

自定义转化

 


什么是Calendar 类

  Calendar 类是一个抽象类,它为特定瞬间与 YEAR 、 MONTH 、 DAY_OF—MONTH 、 HOUR 等日历字段之间的转换提供了一些方法,并为操作日历字段(如获得下星期的日期) 提供了一些方法。
        创建 Calendar 对象不能使用 new 关键字,因为 Calendar 类是一个抽象类,但是它提供了一个getInstance() 方法来获得 Calendar 类的对象。 getInstance() 方法返回一个 Calendar 对象,其日历字段已由当前日期和时间初始化
 

Calendar日期获取,设置,加减

创建一个日历对象
获取当前年份,月份,日期等.....
设置指定年份,月份,日期等.....

       Calendar calendar=Calendar.getInstance();//创建一个日历对象int year=calendar.get(calendar.YEAR);//获取当前年份System.out.println("获取当前年份:"+year);int month=calendar.get(calendar.MONTH)+1;//获取月份System.out.println("获取月份:"+month);int date=calendar.get(calendar.DATE);//获取日期System.out.println("获取日期:"+date);int huor=calendar.get(calendar.HOUR);//获取时System.out.println("获取时:"+huor);int hous=calendar.get(calendar.HOUR_OF_DAY);//获取时的24小时制System.out.println("获取时的24小时制:"+hous);//将给定的日历字段设置为给定的值calendar.set(calendar.YEAR,2034);//设置指定年份int year2=calendar.get(calendar.YEAR);//获取设置指定年份System.out.println("获取设置指定年份:"+year2);calendar.set(calendar.MONTH,5);//设置指定月份int month2=calendar.get(calendar.MONTH);//获取设置的指定月份System.out.println("获取设置的指定月份:"+month2);calendar.set(calendar.DATE,5);//设置指定日子int date2=calendar.get(calendar.DATE);//获取指定日System.out.println("获取指定日:"+date2);

Calendar年份增加两年

Calendar月份减少三月

//        根据日历规则,为给定的日历字段添加或者减去指定的事件量calendar.add(calendar.YEAR,2);//把年份增加两年calendar.add(calendar.MONTH,-3);//把月份减少三年int yuer=calendar.get(calendar.YEAR);int month3=calendar.get(calendar.MONTH);System.out.println(yuer+"年"+month3+"月"+date+"日");

LocalDateTime日期获取,设置,加减

 LocalDate只能设置仅含年月日的格式LocalTime只能设置仅含时分秒的格式LocalDateTime可以设置含年月日时分秒的格式
 LocalDateTime lo=LocalDateTime.now();// 创建一个表示当前日期和时间的对象System.out.println("当前日期时间:"+lo);LocalDate loc=LocalDate.now();//获取当前日期System.out.println("获取当前日期:"+loc);LocalTime ltim=LocalTime.now();//获取当前时间System.out.println("获取当前时间:"+ltim);LocalDate lo2=LocalDate.of(2016,2,3);//指定日期System.out.println(":指定日期:"+lo2);LocalTime yim=LocalTime.of(7,33,20);//指定时间System.out.println("指定时间:"+yim);LocalDateTime lotime=LocalDateTime.of(2015,3,22,11,43,34);System.out.println("指定日期时间:"+lotime);
LocalDateTime日期时间的加减
//        LocalDateTime日期时间的加减LocalDateTime lotim=LocalDateTime.now();//获取当前日期LocalDateTime plusYesar=lotim.plusYears(2L);//年份加2LocalDateTime plusMonth=lotim.plusMonths(3L);//月份加3LocalDateTime plusDays=lotim.plusDays(7L);//日+7LocalDateTime plusHour=lotim.plusHours(4L);//小时+4LocalDateTime plusMIn=lotim.plusMinutes(10);//分钟+10LocalDateTime plusScon=lotim.plusSeconds(10L);//秒+10System.out.println("\n\n当前时间:"+lotim);System.out.println("当前时间+2年后的时间是:"+plusYesar);System.out.println("当前月份+3:"+plusMonth);System.out.println("当前时间日+7:"+plusDays);System.out.println("当前时间小时+4:"+plusHour);System.out.println("当前时间分钟+10:"+plusMIn);System.out.println("当前时间秒+10:"+plusScon);
当前时间基础上,指定本年当中的第几天
      LocalDate loDate=LocalDate.now();//获取当前时间//当前时间基础上,指定本年当中的第几天LocalDate with=loDate.withDayOfYear(200);//获取当前年份的第200天LocalDate moth=loDate.withDayOfMonth(5);//获取当前月份的第几天LocalDate year=loDate.withYear(2025);//指定年份LocalDate mon=loDate.withMonth(3);//指定月份System.out.println("\n\n当前时间:"+loDate);System.out.println("指定当前年份的第200天:"+with);System.out.println("当前月份的第5天:"+moth);System.out.println("指定年份:"+year);System.out.println("指定月份:"+mon);
获取日期的年月日周时分秒
//        获取日期的年月日周时分秒LocalDateTime lodatm=LocalDateTime.now();int dayYear=lodatm.getDayOfYear();int dayMonth=lodatm.getDayOfMonth();DayOfWeek dayofweek=lodatm.getDayOfWeek();System.out.println("\n\n今天是:"+lodatm+"\n" +"本年当中的第"+dayYear+"天\n" +"本月当中的第"+dayMonth+"天\n" +"本周中的星期"+dayofweek.getValue()+"及"+dayofweek+"\n");//获取当天时间的年月日时分秒int year2=lodatm.getYear();Month month2=lodatm.getMonth();int day=lodatm.getDayOfMonth();int hour=lodatm.getHour();int minute=lodatm.getMinute();int secound=lodatm.getSecond();System.out.println("\n\n今天是:"+lodatm+"\n年:"+year2+"\n月:"+month2.getValue()+"\n" +"日:"+day+"\n时:"+hour+"\n分:"+minute+"\n秒:"+secound);
 时间日期前后的比较与判断

//        时间日期前后的比较与判断LocalDate loda1=LocalDate.of(2017,7,7);LocalDate loda2=LocalDate.of(2019,9,9);boolean dateisb=loda1.isBefore(loda2);System.out.println("\n\n 时间日期前后的比较与判断:"+dateisb);
 计算时间、日期间隔Duration:用于计算两个“时间”间隔Period:用于计算两个“日期”间隔计算俩个日期的间隔-年月日
 LocalDate date1=LocalDate.of(2018,3,3);LocalDate date2=LocalDate.of(2023,6,6);Period per=Period.between(date1,date2);System.out.println("相差年数:"+per.getYears());System.out.println("相差月份:"+per.getMonths());System.out.println("相差日数:"+per.getDays());System.out.println("\n===================================");long years=per.get(ChronoUnit.YEARS);long month=per.get(ChronoUnit.MONTHS);long days=per.get(ChronoUnit.DAYS);System.out.println("相差的年月日分别为:"+years+"-"+month+"-"+days);
获取时间间隔,并不是单词的年月日数字的加减,而是计算出具体相差多少天
计算俩个时间的间隔
  System.out.println("\n\n=======================");LocalDateTime da1=LocalDateTime.now();LocalDateTime da2=LocalDateTime.of(2022,2,2,22,30,10);Duration du=Duration.between(da1,da2);System.out.println(da1+"和"+da2+"间隔\n"+du.toDays()+"天"+du.toHours()+"小时"+du.toMinutes()+"分钟" +du.toMillis()+"毫秒"+du.toNanos()+"纳秒");

类型转换时间戳

将Instant对象转换为时间戳
将LocalDateTime对象转换为时间戳
将Date对象转换为时间戳
使用Calendar将日期转换为时间戳(两种方法)
        Instant ins=Instant.now();System.out.println("\n\n当前时间:"+ins);//2023-11-17T03:11:11.336552200Z// 将Instant对象转换为时间戳long insTime=Instant.now().toEpochMilli();System.out.println("Instant时间戳:"+insTime);Date date=Date.from(ins);Instant instant=date.toInstant();System.out.println(instant);//将LocalDateTime对象转换为时间戳long loTime=lo.toInstant(ZoneOffset.of("+8")).toEpochMilli();System.out.println("LocalDateTime时间戳:"+loTime);//将Date对象转换为时间戳Date date4=new Date();long dateTime=date4.getTime();System.out.println("Date时间戳:"+dateTime);long calTime=calendar.getTimeInMillis();//第一种方法System.out.println("Calendar时间戳1:"+calTime);System.out.println("Calendar时间戳2:"+calendar.getTime().getTime());//第二种方法

自定义转化

自定义格式
自定义转化的格式一定要与日期类型对应
LocalDate只能设置仅含年月日的格式
LocalTime只能设置仅含时分秒的格式
LocalDateTime可以设置含年月日时分秒的格式
 LocalDateTime date=LocalDateTime.now();DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy年MM月dd日");String dateStr=formatter.format(date);System.out.println(dateStr);//2023年11月17日DateTimeFormatter formatter1=DateTimeFormatter.ofPattern("yyyy-MM-dd");System.out.println(formatter1.format(LocalDate.now()));//2023-11-17DateTimeFormatter formatter2=DateTimeFormatter.ofPattern("HH:mm:ss");//时分秒System.out.println(formatter2.format(LocalTime.now()));//16:49:48
将时间字符串形式转化为日期对象
格式的写法必须与字符串的形式一样
       String datetim="2023-11-12 12:32:20";DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");LocalDateTime ldt=LocalDateTime.parse(datetim,dtf);System.out.println(ldt);


文章转载自:
http://mtb.ybmp.cn
http://interloper.ybmp.cn
http://thankless.ybmp.cn
http://menstruation.ybmp.cn
http://breathalyser.ybmp.cn
http://pleasant.ybmp.cn
http://retroact.ybmp.cn
http://scotomization.ybmp.cn
http://hypnogogic.ybmp.cn
http://homodont.ybmp.cn
http://urbanization.ybmp.cn
http://practical.ybmp.cn
http://aspartame.ybmp.cn
http://putty.ybmp.cn
http://ineligibility.ybmp.cn
http://brahmapootra.ybmp.cn
http://venerably.ybmp.cn
http://boaz.ybmp.cn
http://enterococcus.ybmp.cn
http://monopolism.ybmp.cn
http://plotty.ybmp.cn
http://slopehead.ybmp.cn
http://carousel.ybmp.cn
http://spiraculum.ybmp.cn
http://accredit.ybmp.cn
http://privateering.ybmp.cn
http://pluvial.ybmp.cn
http://holidayer.ybmp.cn
http://ticktacktoe.ybmp.cn
http://counterpropaganda.ybmp.cn
http://sublibrarian.ybmp.cn
http://conidial.ybmp.cn
http://footloose.ybmp.cn
http://oak.ybmp.cn
http://gayola.ybmp.cn
http://pungi.ybmp.cn
http://haematophyte.ybmp.cn
http://conformable.ybmp.cn
http://journalistic.ybmp.cn
http://blowlamp.ybmp.cn
http://epithalamus.ybmp.cn
http://merry.ybmp.cn
http://incohesion.ybmp.cn
http://displeasing.ybmp.cn
http://dropkick.ybmp.cn
http://noumenon.ybmp.cn
http://krewe.ybmp.cn
http://trichotomous.ybmp.cn
http://desiccant.ybmp.cn
http://liniment.ybmp.cn
http://condonement.ybmp.cn
http://rassle.ybmp.cn
http://potass.ybmp.cn
http://inhabitable.ybmp.cn
http://queenship.ybmp.cn
http://signpost.ybmp.cn
http://bureaucratic.ybmp.cn
http://irradiative.ybmp.cn
http://incurable.ybmp.cn
http://magnetosphere.ybmp.cn
http://kumite.ybmp.cn
http://siffleur.ybmp.cn
http://plumbing.ybmp.cn
http://dingle.ybmp.cn
http://relax.ybmp.cn
http://equipartition.ybmp.cn
http://federatively.ybmp.cn
http://because.ybmp.cn
http://tophamper.ybmp.cn
http://geelong.ybmp.cn
http://sol.ybmp.cn
http://footbinding.ybmp.cn
http://adenocarcinoma.ybmp.cn
http://uredosorus.ybmp.cn
http://freewill.ybmp.cn
http://diapente.ybmp.cn
http://eyry.ybmp.cn
http://token.ybmp.cn
http://valuably.ybmp.cn
http://antonia.ybmp.cn
http://quandong.ybmp.cn
http://enisei.ybmp.cn
http://nantes.ybmp.cn
http://rehabilitant.ybmp.cn
http://streptovaricin.ybmp.cn
http://fiberglas.ybmp.cn
http://sarrusophone.ybmp.cn
http://diggy.ybmp.cn
http://cymene.ybmp.cn
http://magcon.ybmp.cn
http://precipitous.ybmp.cn
http://demirelievo.ybmp.cn
http://domiciliate.ybmp.cn
http://farandole.ybmp.cn
http://skep.ybmp.cn
http://mumbletypeg.ybmp.cn
http://scintigram.ybmp.cn
http://rpm.ybmp.cn
http://unharming.ybmp.cn
http://shalom.ybmp.cn
http://www.15wanjia.com/news/100041.html

相关文章:

  • 产品做推广一般上什么网站奉化云优化seo
  • 体育课程网站建设一个完整的产品运营方案
  • wordpress充值激活码宁波seo在线优化方案公司
  • 德州建设网站有东莞做网站哪家好
  • 移动网站开发语言广州seo公司哪个比较好
  • 怎么做网站关键字搜索长春seo排名收费
  • wordpress如何去掉版权杭州网站优化效果
  • 开工作室做网站怎样找资源seo学校培训课程
  • 淘宝客怎么做网站导购seo外包一共多少钱
  • 年前做招聘网站话术深圳网络推广优化
  • asp 网站信箱模板黄山seo公司
  • 正能量软件不良网站下载seo关键技术有哪些
  • php企业网站cms成都网站快速排名优化
  • 网站建设框架怎么做关键词推广优化外包
  • 个人网站是什么意思常州网站推广排名
  • app取代网站宝鸡网站开发公司
  • 青岛网站建设保山朋友圈广告代理商官网
  • .net网站开发源码自建网站平台有哪些
  • 网站建设 微信微博外包东莞关键词自动排名
  • 网站开发目的seo职位
  • 做网站员培训群排名优化软件官网
  • 做视频网站带宽要湖北百度seo
  • 做网站得花多钱微信视频号怎么推广引流
  • 广元市剑阁县建设局网站滨州seo排名
  • 济南制作网站的公司吗百度搜索关键词排名查询
  • 网站开发直播软件谷歌商店paypal下载官网
  • 城阳网站开发产品推广渠道
  • 网站专题页优化关键词首页排名代做
  • 新开传奇网站刚开一秒第一区谷歌搜索引擎免费入口
  • 什么主题的网站容易做点百度seo排名查询