![java 時(shí)間格式化問題_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/1/fbe3dc90-de8e-4078-a187-ebb9335e0c9d/fbe3dc90-de8e-4078-a187-ebb9335e0c9d1.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、java 時(shí)間格式化問題java.util.*;import java.tt.*;import java.util.calendar; public class vedate /* * 獵取現(xiàn)在時(shí)光 * * return 返回時(shí)光類型 yyyy-mm- hh:mm:ss */ public ic date getnowdate() date currenttime = new date(); simpledatefoat formatter = new simpledateformat("yyyy-mm-dd hh:mm:ss"); sing string = format
2、ter.format(currenttime); parseposition pos = new parseposition(8); date currenttime_2 = formatter.parse(datestring, pos); return currenttime_2; /* * 獵取現(xiàn)在時(shí)光 * * return返回短時(shí)光格式 yyyy-mm-dd */ public static date getnowdateshort() date currenttime = new date(); simpledateformat formatter = new simpledatef
3、ormat("yyyy-mm-dd"); string datestring = formatter.format(currenttime); parseposition pos = new parseposition(8); date currenttime_2 = formatter.parse(datestring, pos); return currenttime_2; /* * 獵取現(xiàn)在時(shí)光 * * return返回字符串格式 yyyy-mm-dd hh:mm:ss */ public static string getstringdate() date curr
4、enttime = new date(); simpledateformat formatter = new simpledateformat("yyyy-mm-dd hh:mm:ss"); string datestring = formatter.format(currenttime); return datestring; /* * 獵取現(xiàn)在時(shí)光 * * return 返回短時(shí)光字符串格式y(tǒng)yyy-mm-dd */ public static string getstringdateshort() date currenttime = new date(); simp
5、ledateformat formatter = new simpledateformat("yyyy-mm-dd"); string datestring = formatter.format(currenttime); return datestring; /* * 獵取時(shí)光 小時(shí):分;秒 hh:mm:ss * * return */ public static string gettimeshort() simpledateformat formatter = new simpledateformat("hh:mm:ss"); date curre
6、nttime = new date(); string datestring = formatter.format(currenttime); return datestring; /* * 將長(zhǎng)時(shí)光格式字符串轉(zhuǎn)換為時(shí)光 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"); parsep
7、osition pos = new parseposition(0); date strtodate = formatter.parse(strdate, pos); return strtodate; /* * 將長(zhǎng)時(shí)光格式時(shí)光轉(zhuǎn)換為字符串 yyyy-mm-dd hh:mm:ss * * param datedate * return */ public static string datetostrlong(java.util.date datedate) simpledateformat formatter = new simpledateformat("yyyy-mm-dd
8、hh:mm:ss"); string datestring = formatter.format(datedate); return datestring; /* * 將短時(shí)光格式時(shí)光轉(zhuǎn)換為字符串 yyyy-mm-dd * * param datedate * param k * return */ public static string datetostr(java.util.date datedate) simpledateformat formatter = new simpledateformat("yyyy-mm-dd"); string datest
9、ring = formatter.format(datedate); return datestring; /* * 將短時(shí)光格式字符串轉(zhuǎn)換為時(shí)光 yyyy-mm-dd * * param strdate * return */ public static date strtodate(string strdate) simpledateformat formatter = new simpledateformat("yyyy-mm-dd"); parseposition pos = new parseposition(0); date strtodate = format
10、ter.parse(strdate, pos); return strtodate; /* * 得到現(xiàn)在時(shí)光 * * return */ public static date getnow() date currenttime = new date(); return currenttime; /* * 提取一個(gè)月中的最后一天 * * param day * return */ public static date getlastdate(long day) date date = new date(); long date_3_hm = date.gettime() - 3600000 *
11、34 * day; date date_3_hm_date = new date(date_3_hm); return date_3_hm_date; /* * 得到現(xiàn)在時(shí)光 * * return 字符串 yyyymmdd hhmmss */ public static string getstringtoday() date currenttime = new date(); simpledateformat formatter = new simpledateformat("yyyymmdd hhmmss"); string datestring = formatter
12、.format(currenttime); return datestring; /* * 得到現(xiàn)在小時(shí) */ public static string gethour() date currenttime = new date(); simpledateformat formatter = new simpledateformat("yyyy-mm-dd hh:mm:ss"); string datestring = formatter.format(currenttime); string hour; hour = datestring.bstring(11, 13);
13、 return hour; /* * 得到現(xiàn)在分鐘 * * return */ public static string gettime() date currenttime = new date(); simpledateformat formatter = new simpledateformat("yyyy-mm-dd hh:mm:ss"); string datestring = formatter.format(currenttime); string min; min = datestring.substring(14, 16); return min; /*
14、* 按照用戶傳入的時(shí)光表示格式,返回當(dāng)前時(shí)光的格式 假如是yyyymmdd,注重字母y不能大寫。 * * param sformat * yyyymmddhhmmss * return */ public static string getuserdate(string sformat) date currenttime = new date(); simpledateformat formatter = new simpledateformat(sformat); string datestring = formatter.format(currenttime); return datestring; /* * 二個(gè)小時(shí)時(shí)光間的差值,必需保證二個(gè)時(shí)光都是"hh:mm"的格式,返回字符型的分鐘 */ public static string gettwohour(string st1, string st2) string kk = null; string jj = null; kk = st1.(":"); jj = st2.split(&
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年企業(yè)機(jī)器質(zhì)押借款合同
- 2025年勞動(dòng)解除合同標(biāo)準(zhǔn)條款
- 2025年抗瘧藥項(xiàng)目申請(qǐng)報(bào)告模范
- 2025年貨車租賃與運(yùn)輸服務(wù)合同樣本
- 2025年國(guó)際貨物買賣合同與慣例
- 2025年專業(yè)清潔人員派遣協(xié)議
- 2025年二手車購(gòu)買合同范本
- 2025年三板市場(chǎng)股權(quán)買賣協(xié)議
- 2025年伙伴開設(shè)教育機(jī)構(gòu)合作協(xié)議書模板
- 2025年繼電器研發(fā)策劃技術(shù)協(xié)議書范本
- JCT796-2013 回彈儀評(píng)定燒結(jié)普通磚強(qiáng)度等級(jí)的方法
- 懸挑腳手架搭設(shè)要求
- 幼兒園衛(wèi)生保健十三種表格
- 勞動(dòng)用工備案表
- 業(yè)務(wù)提成獎(jiǎng)勵(lì)方案
- 四年級(jí)語(yǔ)文上冊(cè)第一單元單元整體教學(xué)設(shè)計(jì)
- 玩具安全標(biāo)準(zhǔn)測(cè)試培訓(xùn)-(SGS)課件
- 員工工資條模板
- 病例報(bào)告表格模板CRF
- 火力發(fā)電廠節(jié)能管理制度實(shí)施細(xì)則
- 《極致挑逗:雙人共撫全圖解120招》讀書筆記模板
評(píng)論
0/150
提交評(píng)論