java 格式化時間的示例代碼
package jkcs;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class jdcs { public static void main(String[] args) throws InterruptedException { System.setProperty('webdriver.chrome.bin','C:Program Files (x86)Mozilla Firefoxfirefox.exe'); //設(shè)置安裝路徑,防止系統(tǒng)找不到 WebDriver driver = new FirefoxDriver(); driver.get('http://www.baidu.com'); driver.manage().window().maximize(); Thread.sleep(5000); driver.manage().window().maximize(); //最大化窗口 driver.navigate().to('https://www.baidu.com'); Thread.sleep(5000); DateFormat dateformat1= new SimpleDateFormat('yyyy-MM-dd'); //創(chuàng)建一個data format對象 Date date1 = new Date(); //利用Date()獲取當(dāng)前時間 String datex = dateformat1.format(date1); //格式化時間,并用String對象存儲 System.out.println(datex); //打印格式化時間到控制臺 DateFormat dateformat2= new SimpleDateFormat('yyyy-MM-dd-HH-mm-ss'); //創(chuàng)建一個data format對象 Date date2 = new Date(); //利用Date()獲取當(dāng)前時間 String datey = dateformat2.format(date2); //格式化時間,并用String對象存儲 System.out.println(datey); //打印格式化時間到控制臺 DateFormat dateformat3= new SimpleDateFormat('HH-mm-ss'); //創(chuàng)建一個data format對象 Date date3 = new Date(); //利用Date()獲取當(dāng)前時間 String dateu = dateformat3.format(date3); //格式化時間,并用String對象存儲 System.out.println(dateu); //打印格式化時間到控制臺 Thread.sleep(5000); driver.quit(); }}
以上就是java 格式化時間的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Java 格式化時間的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. 在layer彈出層中通過ajax返回html拼接字符串填充數(shù)據(jù)的方法2. 存儲于xml中需要的HTML轉(zhuǎn)義代碼3. java volatile案例講解4. asp.net core 中的Jwt(Json Web Token)的使用詳解5. 解決Ajax方式上傳文件報錯"Uncaught TypeError: Illegal invocation"6. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法7. 編寫xml沒有代碼提示的解決方法8. 用xslt將xml解析成xhtml的代碼9. JSP的Cookie在登錄中的使用10. ztree+ajax實(shí)現(xiàn)文件樹下載功能
