Java时间格式转换大全
import .*;
import ar;
public class VeDate {
/**
* 获取现在时间
*
* @return 返回时间类型 yyyy-MM-dd HH:mm:ss
*/
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
ParPosition pos = new ParPosition(8);
Date currentTime_2 = (dateString中华经典诵读篇目, pos);
return currentTime_2;
}
/**
* 获取现在时间
*
* @return返回短时间格式 yyyy-MM-dd
*/
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat format 2= new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date date = null;
String str = null;
// String转Date
str = "2007-1-18";
try {
date = (str);
data = (str);
} catch (ParException e) {
tackTrace();
}
/**
* 获取现在时间
*
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
return dateString;
}
/**
* 获取现在时间
*
* @return 返回短时间字符串格式yyyy-MM-dd
*/
public static String getStringDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = (currentTime);
return dateString;
}
/**
* 获取时间 小时:分;秒 HH:mm:ss
*
* @return
*/
public static String getTimeShort() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date currentTime = new Date();
String dateString = (currentTime);
return dateString;
}
/**
* 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
*
* @param strDate
* @return
*/
public static Date strToDateLong(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParPosition pos = new ParPosition(0);
Date strtodate = (strDate, pos);
return strtodate;
}
/**
* 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
*
* @param dateDate
* @return
*/
public static String dateToStrLong( dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (dateDate);
return dateString;
}
/**
* 将短时间格式时间转换为字符串 yyyy-MM-dd
*
* @param dateDate
* @param k
* @return
*/
public static String dateToStr( dateDate) {
SimpleDateFormat formatter = new SimpleDateForm
at("yyyy-MM-dd");
String dateString = (dateDate);
return dateString;
}
/**
* 将短时间格式字符串转换为时间 yyyy-MM-dd
*
* @param strDate
* @return
*/
public static Date strToDate(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParPosition pos = new ParPosition(0);
Date strtodate = (strDate初一周记300字, pos);
return strtodate;
}
/**
* 得到现在时间
*
* @return
*/
public static Date getNow() {
Date currentTime = new Date();
return currentTime;
}
/**
* 提取一个月中的最后一天
*
* @param day
* @return
*/
public static Date getLastDate(long day) {
Date date = new Date();
long date_3_hm = e() - 3600000 * 34 * day;
Date date_3_hm_date = new Date(date_3_hm);
return date_3_hm_date;
}
/**
* 得到现在时间
*
* @return 字符串 yyyyMMdd HHmmss
*/
public static String getStringToday() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
String dateString = (currentTime);
return dateString;
}
/**
* 得到现在小时
*/
public static String getHour() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
String hour;
hour = ing(11近视调查, 13);
return hour;
}
/**
* 得到现在分钟
*
* @return
*/
public static String getTime() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
String min;
min = ing(14, 16);
return min;
}
/**
* 根据用户传入的时间表示格式2016年春节放假安排时间表,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写开门红幼儿舞蹈。
*
* @param sformat
* yyyyMMddhhmmss
* @return
*/
public static String getUrDate(String sformat) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(sformat);
String dateString = (currentTime);
return dateString;
}
--------------------------------------------------------------------------------------------------------------------------------
做成方法
import 关于学习的名言名句.*;
import .*;
import ar;
public class VeDate {
/**
* 获取现在时间
*
* @return 返回时间类型 yyyy-MM-dd HH:mm:ss
*/
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
ParPosition pos = new ParPosition(8);
Date currentTime_2 = (dateString, pos);
return currentTime_2;
}
/**
* 获
取现在时间
*
* @return返回短时间格式 yyyy-MM-dd
*/
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = (currentTime);
ParPosition pos = new ParPosition(8);
Date currentTime_2 = (dateString, pos);
return currentTime_2;
}
/**
* 获取现在时间
*
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
return dateString;
}
/**
* 获取现在时间
*
* @return 返回短时间字符串格式yyyy-MM-dd
*/
public static String getStringDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = (currentTime);
return dateString;
}
/**
* 获取时间 小时:分;秒 HH:mm:ss
*
* @return
*/
public static String getTimeShort() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date currentTime = new Date();
String dateString = (currentTime);
return dateString;
}
/**
* 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
*
* @param strDate
* @return
*/
public static Date strToDateLong(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParPosition pos = new ParPosition(0);
Date strtodate = (strDate大学新生寄语, pos);
return strtodate;
}
/**
* 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
*
* @param dateDate
* @return
*/
public static String dateToStrLong( dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (dateDate);
return dateString;
}
/**
* 将短时间格式时间转换为字符串 yyyy-MM-dd
*
* @param dateDate
* @param k
* @return
*/
public static String dateToStr( dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = (dateDate);
return dateString;
}
/**
* 将短时间格式字符串转换为时间 yyyy-MM-dd
*
* @param strDate
* @return
*/
public static Date strToDate(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParPosition pos = new ParPosition(0);
Date strtodate = (strDate, pos);
return strtodate;
}
/**
* 得到现在时间
*
* @return
*/
public static Date getNow() {
Date currentTime = new Date();
return currentTime;
}
/**
* 提取一个月中的最后一天
*
* @param day
* @return
*/
public static
Date getLastDate(long day) {
Date date = new Date();
long date_3_hm = e() - 3600000 * 34 * day;
Date date_3_hm_date = new Date(date_3_hm);
return date_3_hm_date;
}
/**
* 得到现在时间
*
* @return 字符串 yyyyMMdd HHmmss
*/
public static String getStringToday() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
String dateString = (currentTime);
return dateString;
}
/**
* 得到现在小时
*/
public static String getHour() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
String hour;
hour = ing(11, 13);
return hour;
}
/**
* 得到现在分钟
*
* @return
*/
public static String getTime() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = (currentTime);
String min;
min = ing(14七夕的由来, 16);
return min;
}
/**
* 根据用户传入的时间表示格式读写绘,返回当前时间的格式 如果是yyyyMMdd国庆节的由来200字,注意字母y不能大写户外广告登记管理规定。
*
* @param sformat
* yyyyMMddhhmmss
* @return
*/
public static String getUrDate(String sformat) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(sformat);
String dateString = (currentTime);
return dateString;
}
/**
* 二个小时时间间的差值,必须保证二个时间都是"HH:MM"的格式,返回字符型的分钟
*/
public static String getTwoHour(String st1, String st2) {
String[] kk = null;
String[] jj = null;
kk = (":");
jj = (":");
if (nt(kk[0]) < nt(jj[0]))
return "0";
el {
double y = ouble(kk[0]) + ouble(kk[1]) / 60;
double u = ouble(jj[0]) + ouble(jj[1]) / 60;
if ((y - u) > 0)
return y - u + "";
el
return "0";
}
}
/**
* 得到二个日期间的间隔天数
*/
public static String getTwoDay(String sj1, String sj2) {
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
long day = 0;
try {
date = (sj1);
mydate = (sj2);
day = (e() - e()) / (24 * 60 * 60 * 1000);
} catch (Exception e) {
return "";
}
return day + "";
}
/**
* 时间前推或后推分钟,其中JJ表示分钟.
*/
public static String getPreTime(String sj1护士节祝福语八个字, String jj) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate1 = "";
try {
Date date1 = (sj1);
long Time = (e() / 1000) + nt(jj) * 60;
e(Time * 100
0);
mydate1 = (date1);
} catch (Exception e) {
}
return mydate1;
}
/**
* 得到一个时间延后或前移几天的时间,nowdate为时间新视野大学英语4课文翻译,delay为前移或后延的天数
*/
public static String getNextDay(String nowdate, String delay) {
try{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String mdate = "";
Date d = strToDate(nowdate);
long myTime = (e() / 1000) + nt(delay) * 24 * 60 * 60;
e(myTime * 1000);
mdate = (d);
return mdate;
}catch(Exception e){
return "";
}
}
/**
* 判断是否润年
*
* @param ddate
* @return
*/
public static boolean isLeapYear(String ddate) {
/**
* 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年
* 3.能被4整除同时能被100整除则不是闰年
*/
Date d = strToDate(ddate);
GregorianCalendar gc = (GregorianCalendar) tance();
e(d);
int year = ();
if ((year % 400) == 0)
return true;
el if ((year % 4) == 0) {
if ((year % 100) == 0)
return fal;
el
return true;
} el
return fal;
}
/**
* 返回美国时间格式 26 Apr 2006
*
* @param str
* @return
*/
public static String getEDate(String str) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParPosition pos = new ParPosition(0);
Date strtodate = (str, pos);
String j = ng();
String[] k = (" ");
return k[2] + k[1].toUpperCa() + k[5]汽车市场分析.substring(2喜欢孤独, 4);
}
/**
* 获取一个月的最后一天
*
* @param dat
* @return
*/
public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
String str = ing(0, 8);
String month = ing(5, 7);
int mon = nt(month);
if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) {
str += "31";
} el if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
str += "30";
} el {
if (isLeapYear(dat)) {
str += "29";
} el {
str += "28";
}
}
return str;
}
/**
* 判断二个时间是否在同一个周
*
* @param date1
* @param date2
* @return
*/
public static boolean isSameWeekDates(Date date1揭开的近义词是什么, Date date2) {
Calendar cal1 = tance();
Calendar cal2 = tance();
e(date1);
e(date2);
int subYear = () - ();
if (0 == subYear) {
if ((_OF_YEAR) == (_OF_YEAR))
return true;
} el if (1 == subYear && 11 == ()) {
// 如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
if ((_OF_YEAR) == ca
(_OF_YEAR))
return true;
} el if (-1 == subYear && 11 == ()) {
if ((_OF_YEAR) == (_OF_YEAR))
return true;
}
return fal;
}
/**
* 产生周序列,即得到当前时间所在的年度是第几周
*
* @return
*/
public static String getSeqWeek() {
Calendar c = tance();
String week = ng((_OF_YEAR));
if (() == 1)
week = "0" + week;
String year = ng(());
return year + week;
}
/**
* 获得一个日期所在的周的星期几的日期,如要找出2002年2月3日所在周的星期一是几号
*
* @param sdate
* @param num
* @return
*/
public static String getWeek(String sdate, String num) {
// 再转换为时间
Date dd = ate(sdate);
Calendar c = tance();
e(dd);
if (("1")) // 返回星期一所在的日期
(_OF_WEEK工程监理规划, );
el if (("2")) // 返回星期二所在的日期
(_OF_WEEK, Y);
el if (("3")) // 返回星期三所在的日期
(_OF_WEEK人教版六年级数学上册教学计划, DAY);
el if (("4")) // 返回星期四所在的日期
(_OF_WEEK两字网名, AY);
el if (("5")) // 返回星期五所在的日期
(_OF_WEEK形近字大全, );
el if (("6")) // 返回星期六所在的日期
(_OF_WEEK, AY);
el if (("0")) // 返回星期日所在的日期
(_OF_WEEK, );
return new SimpleDateFormat("yyyy-MM-dd").format(e());
}
/**
* 根据一个日期时代语录,返回是星期几的字符串
*
* @param sdate
* @return
*/
public static String getWeek(String sdate) {
// 再转换为时间
Date date = ate(sdate);
Calendar c = tance();
e(date);
// int hour=(_OF_WEEK);
// hour中存的就是星期几了真爱酒吧,其范围 1~7
// 1=星期日 7=星期六国庆黄金周,其他类推
return new SimpleDateFormat("EEEE")社区双拥工作计划.format(e());
}
public static String getWeekStr(String sdate){
String str = "";
str = k(sdate);
if("1".equals(str)){
str = "星期日";
}el if("2"淘宝双十一晚会.equals(str)){
str = "星期一";
}el if("3".equals(str)){
str = "星期二";
}el if("4"淡泊以明志 宁静以致远.equals(str)){
str = "星期三";
}el if("5"艾滋病预防知识.equals(str)){
str = "星期四";
}el if("6"婚礼证婚人致辞.equals(str)){
str = "星期五";
}el if("7".equals(str)){
str = "星期六";
}
return str;
}
/**
* 两个时间之间的天数
*
* @param date1
* @param date2
* @return
*/
public static long getDays(String date1人间真情作文, String date2) {
if (d
ate1 == null || (""))
return 0;
if (date2 == null || (""))
return 0;
// 转换为标准时间
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
date = null;
mydate = null;
try {
date = (date1);
mydate = (date2);
} catch (Exception e) {
}
long day = (e() - e()) / (24 * 60 * 60 * 1000);
return day;
}
/**
* 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
* 此函数返回该日历第一行星期日所在的日期
*
* @param sdate
* @return
*/
public static String getNowMonth(String sdate) {
// 取该时间所在月的一号
sdate = ing(0标点符号的故事, 8) + "01";
// 得到这个月的1号是星期几
Date date = ate(sdate);
Calendar c = tance();
e(date);
int u = (_OF_WEEK);
String newday = tDay(sdate茶汤歌词, (1 - u) + "");
return newday;
}
/**
* 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
*
* @param k
* 表示是取几位随机数,可以自己定
*/
public static String getNo(int k) {
return getUrDate("yyyyMMddhhmmss") + getRandom(k);
}
/**
* 返回一个随机数
*
* @param i
* @return
*/
public static String getRandom(int i) {
Random jjj = new Random();
// int suiJiShu = t(9);
if (i == 0)
return "";
String jj = "";
for (int k = 0; k < i; k++) {
jj = jj + t(9);
}
return jj;
}
/**
*
* @param args
*/
public static boolean RightDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
;
if (date == null)
return fal;
if (() > 10) {
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
} el {
sdf = new SimpleDateFormat("yyyy-MM-dd");
}
try {
(date);
} catch (ParException pe) {
return fal;
}
return true;
}
/***************************************************************************
* //nd=1表示返回的值中包含年度 //yf=1表示返回的值中包含月份 //rq=1表示返回的值中包含日期 //format表示返回的格式 1
* 以年月日中文返回 2 以横线-返回 // 3 以斜线/返回 4 以缩写不带其它符号形式返回 // 5 以点号1一6年级必背古诗300首.返回
**************************************************************************/
public static String getStringDateMonth(String sdate道德模范事迹, String nd, String yf泰戈尔的代表作, String rq, String format) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = (currentTime);
String s_nd = ing(0, 4); // 年份
String s_yf = dateStrin
ing(5北京四日游, 7); // 月份
String s_rq = ing(8学习平面设计, 10); // 日期
String sreturn = "";
mc = new ();
if (sdate == null || ("") || !(sdate)) { // 处理空值情况
if (("1")) {
sreturn = s_nd;
// 处理间隔符
if (("1"))
sreturn = sreturn + "年";
el if (("2"))
sreturn = sreturn + "-";
el if (("3"))
sreturn = sreturn + "/";
el if (("5"))
sreturn = sreturn + ".";
}
// 处理月份
if (("1")) {
sreturn = sreturn + s_yf;
if (("1"))
sreturn = sreturn + "月";
el if (("2"))
sreturn = sreturn + "-";
el if (("3"))
sreturn = sreturn + "/";
el if (("5"))
sreturn = sreturn + ".";
}
// 处理日期
if (("1")) {
sreturn = sreturn + s_rq;
if (("1"))
sreturn = sreturn + "日";
}
} el {
// 不是空值,也是一个合法的日期值法制教育主题班会教案,则先将其转换为标准的时间格式
sdate = ate(sdate);
s_nd = ing(0新学期打算作文, 4); // 年份
s_yf = ing(5化肥销售, 7); // 月份
s_rq = ing(8, 10); // 日期
if (("1")) {
sreturn = s_nd;
// 处理间隔符
if (("1"))
sreturn = sreturn + "年";
el if (("2"))
sreturn = sreturn + "-";
el if (("3"))
sreturn = sreturn + "/";
el if (("5"))
sreturn = sreturn + "原来爱情那么难歌词.";
}
// 处理月份
if (("1")) {
sreturn = sreturn + s_yf;
if (("1"))
sreturn = sreturn + "月";
el if (("2"))
sreturn = sreturn + "-";
el if (("3"))
sreturn = sreturn + "/";
el if (("5"))
sreturn = sreturn + ".";
}
// 处理日期
if (("1")) {
sreturn = sreturn + s_rq;
if (("1"))
sreturn = sreturn + "日";
}
}
return sreturn;
}
public static String getNextMonthDay(String sdate, int m) {
sdate = getOKDate(sdate);
int year = nt(ing(0孺子可教的意思, 4));
int month = nt(ing(5, 7));
month = month + m;
if (month < 0) {
month = month + 12;
year = year - 1;
} el if (month > 12) {
month = month - 12;
year = year + 1;
}
String smonth = "";
if (month < 10)
smonth = "0" + month;
el
smonth = "" + month;
return year + "-" + smonth + "-10";
}
public static String getOKDate(String sdate) {
if (sdate == null || (""))
return getStringDateShort();
if (!(sdate)) {
sdate = getStringDateShort();
}
// 将“/”转换为“-”
sdate = e(sdate氧气的物理性质, "/", "-");
// 如果
只有8位长度,则要进行转换
if (() == 8)
sdate = ing(0, 4) + "-" + ing(4春节祝福, 6) + "-" + ing(6合作作文, 8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParPosition pos = new ParPosition(0);
Date strtodate = (sdate护理品管圈, pos);
String dateString = (strtodate);
return dateString;
}
public static void main(String[] args) throws Exception {
try {
//(f(getTwoDay("2006-11-03 12:22:10"三朝名臣言行录, "2006-11-02 11:22:09")));
} catch (Exception e) {
throw new Exception();
}
//n("sss");
}
本文发布于:2022-10-19 22:25:33,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/86/325377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |