技术标签: java int类型 转换date
/*** 获取现在时间,这个好用
*
* @return返回长时间格式 yyyy-MM-dd HH:mm:ss*/
public staticDate getSqlDate() {
Date sqlDate= new java.sql.Date(newDate().getTime());returnsqlDate;
}/*** 获取现在时间
*
* @return返回长时间格式 yyyy-MM-dd HH:mm:ss*/
public staticDate getNowDate() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
ParsePosition pos= new ParsePosition(8);
Date currentTime_2=formatter.parse(dateString, pos);returncurrentTime_2;
}/*** 获取现在时间
*
* @return返回短时间格式 yyyy-MM-dd*/
public staticDate getNowDateShort() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
ParsePosition pos= new ParsePosition(8);
Date currentTime_2=formatter.parse(dateString, pos);returncurrentTime_2;
}/*** 获取现在时间
*
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss*/
public staticString getStringDate() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);returndateString;
}/*** 获取现在时间
*
*@return返回短时间字符串格式yyyy-MM-dd*/
public staticString getStringDateShort() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);returndateString;
}/*** 获取时间 小时:分;秒 HH:mm:ss
*
*@return
*/
public staticString getTimeShort() {
SimpleDateFormat formatter= new SimpleDateFormat("HH:mm:ss");
Date currentTime= newDate();
String dateString=formatter.format(currentTime);returndateString;
}/*** 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
*
*@paramstrDate
*@return
*/
public staticDate strToDateLong(String strDate) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos= new ParsePosition(0);
Date strtodate=formatter.parse(strDate, pos);returnstrtodate;
}/*** 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
*
*@paramdateDate
*@return
*/
public staticString dateToStrLong(java.util.Date dateDate) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(dateDate);returndateString;
}/*** 将短时间格式时间转换为字符串 yyyy-MM-dd
*
*@paramdateDate
*@paramk
*@return
*/
public staticString dateToStr(java.util.Date dateDate) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(dateDate);returndateString;
}/*** 将短时间格式字符串转换为时间 yyyy-MM-dd
*
*@paramstrDate
*@return
*/
public staticDate strToDate(String strDate) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos= new ParsePosition(0);
Date strtodate=formatter.parse(strDate, pos);returnstrtodate;
}/*** 得到现在时间
*
*@return
*/
public staticDate getNow() {
Date currentTime= newDate();returncurrentTime;
}/*** 提取一个月中的最后一天
*
*@paramday
*@return
*/
public static Date getLastDate(longday) {
Date date= newDate();long date_3_hm = date.getTime() - 3600000 * 34 *day;
Date date_3_hm_date= newDate(date_3_hm);returndate_3_hm_date;
}/*** 得到现在时间
*
*@return字符串 yyyyMMdd HHmmss*/
public staticString getStringToday() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMdd HHmmss");
String dateString=formatter.format(currentTime);returndateString;
}/*** 得到现在小时*/
public staticString getHour() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
String hour;
hour= dateString.substring(11, 13);returnhour;
}/*** 得到现在分钟
*
*@return
*/
public staticString getTime() {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
String min;
min= dateString.substring(14, 16);returnmin;
}/*** 根据用户传入的时间表示格式,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写。
*
*@paramsformat
* yyyyMMddhhmmss
*@return
*/
public staticString getUserDate(String sformat) {
Date currentTime= newDate();
SimpleDateFormat formatter= newSimpleDateFormat(sformat);
String dateString=formatter.format(currentTime);returndateString;
}/*** 二个小时时间间的差值,必须保证二个时间都是"HH:MM"的格式,返回字符型的分钟*/
public staticString getTwoHour(String st1, String st2) {
String[] kk= null;
String[] jj= null;
kk= st1.split(":");
jj= st2.split(":");if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))return "0";else{double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1])/ 60;double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1])/ 60;if ((y - u) > 0)return y - u + "";else
return "0";
}
}/*** 得到二个日期间的间隔天数*/
public staticString getTwoDay(String sj1, String sj2) {
SimpleDateFormat myFormatter= new SimpleDateFormat("yyyy-MM-dd");long day = 0;try{
java.util.Date date=myFormatter.parse(sj1);
java.util.Date mydate=myFormatter.parse(sj2);
day= (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
}catch(Exception e) {return "";
}return day + "";
}/*** 时间前推或后推分钟,其中JJ表示分钟.*/
public staticString getPreTime(String sj1, String jj) {
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate1= "";try{
Date date1=format.parse(sj1);long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
date1.setTime(Time* 1000);
mydate1=format.format(date1);
}catch(Exception e) {
}returnmydate1;
}/*** 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数*/
public staticString getNextDay(String nowdate, String delay) {try{
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd");
String mdate= "";
Date d=strToDate(nowdate);long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24
* 60 * 60;
d.setTime(myTime* 1000);
mdate=format.format(d);returnmdate;
}catch(Exception e) {return "";
}
}/*** 判断是否润年
*
*@paramddate
*@return
*/
public static booleanisLeapYear(String ddate) {/*** 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年
* 3.能被4整除同时能被100整除则不是闰年*/Date d=strToDate(ddate);
GregorianCalendar gc=(GregorianCalendar) Calendar.getInstance();
gc.setTime(d);int year =gc.get(Calendar.YEAR);if ((year % 400) == 0)return true;else if ((year % 4) == 0) {if ((year % 100) == 0)return false;else
return true;
}else
return false;
}/*** 返回美国时间格式 26 Apr 2006
*
*@paramstr
*@return
*/
public staticString getEDate(String str) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos= new ParsePosition(0);
Date strtodate=formatter.parse(str, pos);
String j=strtodate.toString();
String[] k= j.split(" ");return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
}/*** 获取一个月的最后一天
*
*@paramdat
*@return
*/
public static String getEndDateOfMonth(String dat) {//yyyy-MM-dd
String str = dat.substring(0, 8);
String month= dat.substring(5, 7);int mon =Integer.parseInt(month);if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8
|| mon == 10 || mon == 12) {
str+= "31";
}else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
str+= "30";
}else{if(isLeapYear(dat)) {
str+= "29";
}else{
str+= "28";
}
}returnstr;
}/*** 判断二个时间是否在同一个周
*
*@paramdate1
*@paramdate2
*@return
*/
public static booleanisSameWeekDates(Date date1, Date date2) {
Calendar cal1=Calendar.getInstance();
Calendar cal2=Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);int subYear = cal1.get(Calendar.YEAR) -cal2.get(Calendar.YEAR);if (0 ==subYear) {if (cal1.get(Calendar.WEEK_OF_YEAR) ==cal2
.get(Calendar.WEEK_OF_YEAR))return true;
}else if (1 == subYear && 11 ==cal2.get(Calendar.MONTH)) {//如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
if (cal1.get(Calendar.WEEK_OF_YEAR) ==cal2
.get(Calendar.WEEK_OF_YEAR))return true;
}else if (-1 == subYear && 11 ==cal1.get(Calendar.MONTH)) {if (cal1.get(Calendar.WEEK_OF_YEAR) ==cal2
.get(Calendar.WEEK_OF_YEAR))return true;
}return false;
}/*** 产生周序列,即得到当前时间所在的年度是第几周
*
*@return
*/
public staticString getSeqWeek() {
Calendar c=Calendar.getInstance(Locale.CHINA);
String week=Integer.toString(c.get(Calendar.WEEK_OF_YEAR));if (week.length() == 1)
week= "0" +week;
String year=Integer.toString(c.get(Calendar.YEAR));return year +week;
}/*** 获得一个日期所在的周的星期几的日期,如要找出2002年2月3日所在周的星期一是几号
*
*@paramsdate
*@paramnum
*@return
*/
public staticString getWeek(String sdate, String num) {//再转换为时间
Date dd =strToDate(sdate);
Calendar c=Calendar.getInstance();
c.setTime(dd);if (num.equals("1")) //返回星期一所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);else if (num.equals("2")) //返回星期二所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);else if (num.equals("3")) //返回星期三所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);else if (num.equals("4")) //返回星期四所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);else if (num.equals("5")) //返回星期五所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);else if (num.equals("6")) //返回星期六所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);else if (num.equals("0")) //返回星期日所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
}/*** 根据一个日期,返回是星期几的字符串
*
*@paramsdate
*@return
*/
public staticString getWeek(String sdate) {//再转换为时间
Date date =strToDate(sdate);
Calendar c=Calendar.getInstance();
c.setTime(date);//int hour=c.get(Calendar.DAY_OF_WEEK);//hour中存的就是星期几了,其范围 1~7//1=星期日 7=星期六,其他类推
return new SimpleDateFormat("EEEE").format(c.getTime());
}public staticString getWeekStr(String sdate) {
String str= "";
str=getWeek(sdate);if ("1".equals(str)) {
str= "星期日";
}else if ("2".equals(str)) {
str= "星期一";
}else if ("3".equals(str)) {
str= "星期二";
}else if ("4".equals(str)) {
str= "星期三";
}else if ("5".equals(str)) {
str= "星期四";
}else if ("6".equals(str)) {
str= "星期五";
}else if ("7".equals(str)) {
str= "星期六";
}returnstr;
}/*** 两个时间之间的天数
*
*@paramdate1
*@paramdate2
*@return
*/
public static longgetDays(String date1, String date2) {if (date1 == null || date1.equals(""))return 0;if (date2 == null || date2.equals(""))return 0;//转换为标准时间
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date= null;
java.util.Date mydate= null;try{
date=myFormatter.parse(date1);
mydate=myFormatter.parse(date2);
}catch(Exception e) {
}long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);returnday;
}/*** 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
* 此函数返回该日历第一行星期日所在的日期
*
*@paramsdate
*@return
*/
public staticString getNowMonth(String sdate) {//取该时间所在月的一号
sdate = sdate.substring(0, 8) + "01";//得到这个月的1号是星期几
Date date =strToDate(sdate);
Calendar c=Calendar.getInstance();
c.setTime(date);int u =c.get(Calendar.DAY_OF_WEEK);
String newday= getNextDay(sdate, (1 - u) + "");returnnewday;
}/*** 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
*
*@paramk
* 表示是取几位随机数,可以自己定*/
public static String getNo(intk) {return getUserDate("yyyyMMddhhmmss") +getRandom(k);
}/*** 返回一个随机数
*
*@parami
*@return
*/
public static String getRandom(inti) {
Random jjj= newRandom();//int suiJiShu = jjj.nextInt(9);
if (i == 0)return "";
String jj= "";for (int k = 0; k < i; k++) {
jj= jj + jjj.nextInt(9);
}returnjj;
}/***@paramargs*/
public static booleanRightDate(String date) {
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
;if (date == null)return false;if (date.length() > 10) {
sdf= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
}else{
sdf= new SimpleDateFormat("yyyy-MM-dd");
}try{
sdf.parse(date);
}catch(ParseException pe) {return false;
}return true;
}/***************************************************************************
* //nd=1表示返回的值中包含年度 //yf=1表示返回的值中包含月份 //rq=1表示返回的值中包含日期 //format表示返回的格式 1
* 以年月日中文返回 2 以横线-返回 // 3 以斜线/返回 4 以缩写不带其它符号形式返回 // 5 以点号.返回
**************************************************************************/
public staticString getStringDateMonth(String sdate, String nd, String yf,
String rq, String format) {
Date currentTime= newDate();
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
String s_nd= dateString.substring(0, 4); //年份
String s_yf = dateString.substring(5, 7); //月份
String s_rq = dateString.substring(8, 10); //日期
String sreturn = "";if (sdate == null || sdate.equals("") || !Isdate(sdate)) { //处理空值情况
if (nd.equals("1")) {
sreturn=s_nd;//处理间隔符
if (format.equals("1"))
sreturn= sreturn + "年";else if (format.equals("2"))
sreturn= sreturn + "-";else if (format.equals("3"))
sreturn= sreturn + "/";else if (format.equals("5"))
sreturn= sreturn + ".";
}//处理月份
if (yf.equals("1")) {
sreturn= sreturn +s_yf;if (format.equals("1"))
sreturn= sreturn + "月";else if (format.equals("2"))
sreturn= sreturn + "-";else if (format.equals("3"))
sreturn= sreturn + "/";else if (format.equals("5"))
sreturn= sreturn + ".";
}//处理日期
if (rq.equals("1")) {
sreturn= sreturn +s_rq;if (format.equals("1"))
sreturn= sreturn + "日";
}
}else{//不是空值,也是一个合法的日期值,则先将其转换为标准的时间格式//sdate = roc.util.RocDate.getOKDate(sdate);
s_nd = sdate.substring(0, 4); //年份
s_yf = sdate.substring(5, 7); //月份
s_rq = sdate.substring(8, 10); //日期
if (nd.equals("1")) {
sreturn=s_nd;//处理间隔符
if (format.equals("1"))
sreturn= sreturn + "年";else if (format.equals("2"))
sreturn= sreturn + "-";else if (format.equals("3"))
sreturn= sreturn + "/";else if (format.equals("5"))
sreturn= sreturn + ".";
}//处理月份
if (yf.equals("1")) {
sreturn= sreturn +s_yf;if (format.equals("1"))
sreturn= sreturn + "月";else if (format.equals("2"))
sreturn= sreturn + "-";else if (format.equals("3"))
sreturn= sreturn + "/";else if (format.equals("5"))
sreturn= sreturn + ".";
}//处理日期
if (rq.equals("1")) {
sreturn= sreturn +s_rq;if (format.equals("1"))
sreturn= sreturn + "日";
}
}returnsreturn;
}public static String getNextMonthDay(String sdate, intm) {
sdate=getOKDate(sdate);int year = Integer.parseInt(sdate.substring(0, 4));int month = Integer.parseInt(sdate.substring(5, 7));
month= month +m;if (month < 0) {
month= month + 12;
year= year - 1;
}else if (month > 12) {
month= month - 12;
year= year + 1;
}
String smonth= "";if (month < 10)
smonth= "0" +month;elsesmonth= "" +month;return year + "-" + smonth + "-10";
}public staticString getOKDate(String sdate) {if (sdate == null || sdate.equals(""))returngetStringDateShort();if (!Isdate(sdate)) {
sdate=getStringDateShort();
}//将“/”转换为“-”
sdate = sdate.replace("/", "-");//如果只有8位长度,则要进行转换
if (sdate.length() == 8)
sdate= sdate.substring(0, 4) + "-" + sdate.substring(4, 6) + "-"
+ sdate.substring(6, 8);
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos= new ParsePosition(0);
Date strtodate=formatter.parse(sdate, pos);
String dateString=formatter.format(strtodate);returndateString;
}public static void main(String[] args) throwsException {try{//System.out.print(Integer.valueOf(getTwoDay("2006-11-03 12:22:10",//"2006-11-02 11:22:09")));
} catch(Exception e) {throw newException();
}//System.out.println("sss");
}
文章浏览阅读645次。这个肯定是末尾的IDAT了,因为IDAT必须要满了才会开始一下个IDAT,这个明显就是末尾的IDAT了。,对应下面的create_head()代码。,对应下面的create_tail()代码。不要考虑爆破,我已经试了一下,太多情况了。题目来源:UNCTF。_攻防世界困难模式攻略图文
文章浏览阅读2.9k次,点赞3次,收藏10次。偶尔会用到,记录、分享。1. 数据库导出1.1 切换到dmdba用户su - dmdba1.2 进入达梦数据库安装路径的bin目录,执行导库操作 导出语句:./dexp cwy_init/[email protected]:5236 file=cwy_init.dmp log=cwy_init_exp.log 注释: cwy_init/init_123..._达梦数据库导入导出
文章浏览阅读1.9k次。1. 在官网上下载KindEditor文件,可以删掉不需要要到的jsp,asp,asp.net和php文件夹。接着把文件夹放到项目文件目录下。2. 修改html文件,在页面引入js文件:<script type="text/javascript" src="./kindeditor/kindeditor-all.js"></script><script type="text/javascript" src="./kindeditor/lang/zh-CN.js"_kindeditor.js
文章浏览阅读2.3k次,点赞6次,收藏14次。SPI的详情简介不必赘述。假设我们通过SPI发送0xAA,我们的数据线就会变为10101010,通过修改不同的内容,即可修改SPI中0和1的持续时间。比如0xF0即为前半周期为高电平,后半周期为低电平的状态。在SPI的通信模式中,CPHA配置会影响该实验,下图展示了不同采样位置的SPI时序图[1]。CPOL = 0,CPHA = 1:CLK空闲状态 = 低电平,数据在下降沿采样,并在上升沿移出CPOL = 0,CPHA = 0:CLK空闲状态 = 低电平,数据在上升沿采样,并在下降沿移出。_stm32g431cbu6
文章浏览阅读1.2k次,点赞2次,收藏8次。数据链路层习题自测问题1.数据链路(即逻辑链路)与链路(即物理链路)有何区别?“电路接通了”与”数据链路接通了”的区别何在?2.数据链路层中的链路控制包括哪些功能?试讨论数据链路层做成可靠的链路层有哪些优点和缺点。3.网络适配器的作用是什么?网络适配器工作在哪一层?4.数据链路层的三个基本问题(帧定界、透明传输和差错检测)为什么都必须加以解决?5.如果在数据链路层不进行帧定界,会发生什么问题?6.PPP协议的主要特点是什么?为什么PPP不使用帧的编号?PPP适用于什么情况?为什么PPP协议不_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输
文章浏览阅读587次。软件测试工程师移民加拿大 无证移民,未受过软件工程师的教育(第1部分) (Undocumented Immigrant With No Education to Software Engineer(Part 1))Before I start, I want you to please bear with me on the way I write, I have very little gen...
文章浏览阅读304次。Thinkpad X250笔记本电脑,装的是FreeBSD,进入BIOS修改虚拟化配置(其后可能是误设置了安全开机),保存退出后系统无法启动,显示:secure boot failed ,把自己惊出一身冷汗,因为这台笔记本刚好还没开始做备份.....根据错误提示,到bios里面去找相关配置,在Security里面找到了Secure Boot选项,发现果然被设置为Enabled,将其修改为Disabled ,再开机,终于正常启动了。_安装完系统提示secureboot failure
文章浏览阅读10w+次,点赞93次,收藏352次。1、用strtok函数进行字符串分割原型: char *strtok(char *str, const char *delim);功能:分解字符串为一组字符串。参数说明:str为要分解的字符串,delim为分隔符字符串。返回值:从str开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。其它:strtok函数线程不安全,可以使用strtok_r替代。示例://借助strtok实现split#include <string.h>#include <stdio.h&_c++ 字符串分割
文章浏览阅读2.3k次。1 .高斯日记 大数学家高斯有个好习惯:无论如何都要记日记。他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?高斯出生于:1777年4月30日。在高斯发现的一个重要定理的日记_2013年第四届c a组蓝桥杯省赛真题解答
文章浏览阅读851次,点赞17次,收藏22次。摘要:本文利用供需算法对核极限学习机(KELM)进行优化,并用于分类。
文章浏览阅读1.1k次。一、系统弱密码登录1、在kali上执行命令行telnet 192.168.26.1292、Login和password都输入msfadmin3、登录成功,进入系统4、测试如下:二、MySQL弱密码登录:1、在kali上执行mysql –h 192.168.26.129 –u root2、登录成功,进入MySQL系统3、测试效果:三、PostgreSQL弱密码登录1、在Kali上执行psql -h 192.168.26.129 –U post..._metasploitable2怎么进入
文章浏览阅读257次。本文将为初学者提供Python学习的详细指南,从Python的历史、基础语法和数据类型到面向对象编程、模块和库的使用。通过本文,您将能够掌握Python编程的核心概念,为今后的编程学习和实践打下坚实基础。_python人工智能开发从入门到精通pdf