java date获取年月日时分秒的实现方法

package com.util;

import java.text.dateformat;

import java.util.calendar;

import java.util.date;

public class test {

public void gettimebydate(){

date date = new date();

dateformat df1 = dateformat.getdateinstance();//日期格式,精确到日

system.out.println(df1.format(date));

dateformat df2 = dateformat.getdatetimeinstance();//可以精确到时分秒

system.out.println(df2.format(date));

dateformat df3 = dateformat.gettimeinstance();//只显示出时分秒

system.out.println(df3.format(date));

dateformat df4 = dateformat.getdatetimeinstance(dateformat.full,dateformat.full); //显示日期,周,上下午,时间(精确到秒)

system.out.println(df4.format(date));

dateformat df5 = dateformat.getdatetimeinstance(dateformat.long,dateformat.long); //显示日期,上下午,时间(精确到秒)

system.out.println(df5.format(date));

dateformat df6 = dateformat.getdatetimeinstance(dateformat.short,dateformat.short); //显示日期,上下午,时间(精确到分)

system.out.println(df6.format(date));

dateformat df7 = dateformat.getdatetimeinstance(dateformat.medium,dateformat.medium); //显示日期,时间(精确到分)

system.out.println(df7.format(date));

}

public void gettimebycalendar(){

calendar cal = calendar.getinstance();

int year = cal.get(calendar.year);//获取年份

int month=cal.get(calendar.month);//获取月份

int day=cal.get(calendar.date);//获取日

int hour=cal.get(calendar.hour);//小时

int minute=cal.get(calendar.minute);//分

int second=cal.get(calendar.second);//秒

int weekofyear = cal.get(calendar.day_of_week);//一周的第几天

system.out.println("现在的时间是:公元"+year+"年"+month+"月"+day+"日 "+hour+"时"+minute+"分"+second+"秒 星期"+weekofyear);

}

public static void main(string[] args) {

test t=new test();

t.gettimebydate();

system.out.println("****************************");

t.gettimebycalendar();

}

}

获取日,如果大于16则+2个月,否则+1个月,输出7个月

public static void main(string[] as) throws exception {

int j;

calendar cc = calendar.getinstance();

int myyear = cc.get(calendar.year);

int mymonth = cc.get(calendar.month);

j=cc.get(calendar.date)>16?3:2;

cc.set(calendar.month, mymonth+j);

system.out.println(myyear+"-"+cc.get(cc.month));

for(int i=0;i<7;i++){

cc.add(cc.month, 1);

int mm = cc.get(cc.month);

int mmm=mm==0?12:mm;

system.out.println(myyear+"-"+mmm);

}

}

以上这篇java date获取年月日时分秒的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持萬仟网。

希望与广大网友互动??

点此进行留言吧!

java去掉date分时秒_java Date获取年月日时分秒的实现方法相关推荐

  1. java Date获取 年月日时分秒

    转载自   java Date获取 年月日时分秒 package com.util;import java.text.DateFormat; import java.util.Calendar; im ...

  2. php 获取 年月日时分秒_JS获取年月日时分秒的方法分析

    本文实例分析了JS获取年月日时分秒的方法.分享给大家供大家参考,具体如下: var d = new Date(); var time = d.getFullYear() + "-" ...

  3. js获取年月日 时分秒的日期格式

    const date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 >= 10 ? ...

  4. oracle在数据表中获取年月日时分秒

    最近在用oracle数据库select数据,因为之前都是在用mysql,总是会遇到一些问题,记录一下. 如时间的取出问题,在数据库中格式是"年-月-日 时:分:秒"的格式,但是取出 ...

  5. oracle中获取年月日时分秒

    我写sql的时间为2016年10月10日下午15:18完事,这个时间下面要做对比: --获取年 select to_char(sysdate,'yyyy') from dual--2016 selec ...

  6. java时间格式年月日时分秒_java日期格式(年月日时分秒毫秒)

    java日期格式(年月日时分秒毫秒) 2020-08-13 07:09 阅读数 79 package test.remote.tools.combine; import java.text.Simpl ...

  7. android获取年月日时分秒毫秒,Android获取两个日期其间间隔的天数

    /** * 获取两个日期之间的间隔天数 * @return */ public static int getGapCount(Date startDate, Date endDate) { Calen ...

  8. android 字符串 时间格式化,Android 获取年月日时分秒 格式化指定时间字符串

    1.获取Android系统当前时间年月日 时分秒(24小时制) //获取当前时间 Time time=new Time(); time.setToNow(); Log.i("cp" ...

  9. android 如何获得时间格式,Android 获取年月日时分秒 格式化指定时间字符串

    分享一下我老师大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow 1.获取Andro ...

最新文章

  1. JAVA计算应缴住房基金,事业单位的住房基金如何核算?
  2. python文件传输模块_如何将python对象从一个文件模块传递到另一个文件模块?
  3. UVA1343 The Rotation Game旋转游戏
  4. Android应用程序开发环境的建立
  5. mngoDB 常用语法
  6. 简要分析JM8.6代码中foreman_part_qcif.yuv文件的YUV数据如何悄无声息地进入程序
  7. listview复用机制研究
  8. 大数据平台安全问题有哪些
  9. 转载:诠释Flash的职业发展道路
  10. [高通MSM8953_64][Android10]移除开机进入充电界面
  11. 高程数据下载——DLR_SRTM_说明
  12. 一作发表6篇论文!他博三才出科研成果,厚积薄发终获成功
  13. [ kvm ] 学习笔记 1:Linux 操作系统及虚拟化
  14. 25岁文科女转行软件测试之路
  15. 安装office2016后文档表格不能显示图标
  16. 软件测试基础知识 - 说一说黑盒与白盒的测试方法
  17. PV、UV、VV、IP及其关系与计算
  18. Android CMake 编译so库
  19. Spring Cloud教程(八)云原生应用程序
  20. 在安装了zonealarm的机器上实现共享上网

热门文章

  1. “火星人”马斯克推论:世界很大可能性是被编程的,上帝可能是个程序员!
  2. 从左上角到右下角 棋盘问题_分治算法之棋盘问题
  3. new String[0]的作用
  4. Django中的跨域解决办法 基于后端的跨域解决方案
  5. 王半仙儿的日记-0006
  6. coj_1224: ACM小组的古怪象棋
  7. 考研联系导师全攻略!
  8. 什么是大数据 大数据的特点
  9. 《UML正日薄西山的13个理由》读后感
  10. public,nbsp;private,nbsp;prote…