java去掉date分时秒_java Date获取年月日时分秒的实现方法
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获取年月日时分秒的实现方法相关推荐
- java Date获取 年月日时分秒
转载自 java Date获取 年月日时分秒 package com.util;import java.text.DateFormat; import java.util.Calendar; im ...
- php 获取 年月日时分秒_JS获取年月日时分秒的方法分析
本文实例分析了JS获取年月日时分秒的方法.分享给大家供大家参考,具体如下: var d = new Date(); var time = d.getFullYear() + "-" ...
- js获取年月日 时分秒的日期格式
const date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 >= 10 ? ...
- oracle在数据表中获取年月日时分秒
最近在用oracle数据库select数据,因为之前都是在用mysql,总是会遇到一些问题,记录一下. 如时间的取出问题,在数据库中格式是"年-月-日 时:分:秒"的格式,但是取出 ...
- oracle中获取年月日时分秒
我写sql的时间为2016年10月10日下午15:18完事,这个时间下面要做对比: --获取年 select to_char(sysdate,'yyyy') from dual--2016 selec ...
- java时间格式年月日时分秒_java日期格式(年月日时分秒毫秒)
java日期格式(年月日时分秒毫秒) 2020-08-13 07:09 阅读数 79 package test.remote.tools.combine; import java.text.Simpl ...
- android获取年月日时分秒毫秒,Android获取两个日期其间间隔的天数
/** * 获取两个日期之间的间隔天数 * @return */ public static int getGapCount(Date startDate, Date endDate) { Calen ...
- android 字符串 时间格式化,Android 获取年月日时分秒 格式化指定时间字符串
1.获取Android系统当前时间年月日 时分秒(24小时制) //获取当前时间 Time time=new Time(); time.setToNow(); Log.i("cp" ...
- android 如何获得时间格式,Android 获取年月日时分秒 格式化指定时间字符串
分享一下我老师大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow 1.获取Andro ...
最新文章
- JAVA计算应缴住房基金,事业单位的住房基金如何核算?
- python文件传输模块_如何将python对象从一个文件模块传递到另一个文件模块?
- UVA1343 The Rotation Game旋转游戏
- Android应用程序开发环境的建立
- mngoDB 常用语法
- 简要分析JM8.6代码中foreman_part_qcif.yuv文件的YUV数据如何悄无声息地进入程序
- listview复用机制研究
- 大数据平台安全问题有哪些
- 转载:诠释Flash的职业发展道路
- [高通MSM8953_64][Android10]移除开机进入充电界面
- 高程数据下载——DLR_SRTM_说明
- 一作发表6篇论文!他博三才出科研成果,厚积薄发终获成功
- [ kvm ] 学习笔记 1:Linux 操作系统及虚拟化
- 25岁文科女转行软件测试之路
- 安装office2016后文档表格不能显示图标
- 软件测试基础知识 - 说一说黑盒与白盒的测试方法
- PV、UV、VV、IP及其关系与计算
- Android CMake 编译so库
- Spring Cloud教程(八)云原生应用程序
- 在安装了zonealarm的机器上实现共享上网