java 格式化時(shí)間的示例代碼
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)建一個(gè)data format對(duì)象 Date date1 = new Date(); //利用Date()獲取當(dāng)前時(shí)間 String datex = dateformat1.format(date1); //格式化時(shí)間,并用String對(duì)象存儲(chǔ) System.out.println(datex); //打印格式化時(shí)間到控制臺(tái) DateFormat dateformat2= new SimpleDateFormat('yyyy-MM-dd-HH-mm-ss'); //創(chuàng)建一個(gè)data format對(duì)象 Date date2 = new Date(); //利用Date()獲取當(dāng)前時(shí)間 String datey = dateformat2.format(date2); //格式化時(shí)間,并用String對(duì)象存儲(chǔ) System.out.println(datey); //打印格式化時(shí)間到控制臺(tái) DateFormat dateformat3= new SimpleDateFormat('HH-mm-ss'); //創(chuàng)建一個(gè)data format對(duì)象 Date date3 = new Date(); //利用Date()獲取當(dāng)前時(shí)間 String dateu = dateformat3.format(date3); //格式化時(shí)間,并用String對(duì)象存儲(chǔ) System.out.println(dateu); //打印格式化時(shí)間到控制臺(tái) Thread.sleep(5000); driver.quit(); }}
以上就是java 格式化時(shí)間的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Java 格式化時(shí)間的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Python如何批量生成和調(diào)用變量2. Python調(diào)用接口合并Excel表代碼實(shí)例3. python 爬取京東指定商品評(píng)論并進(jìn)行情感分析4. ajax動(dòng)態(tài)加載json數(shù)據(jù)并詳細(xì)解析5. ASP.NET MVC實(shí)現(xiàn)橫向展示購(gòu)物車(chē)6. ASP.Net Core(C#)創(chuàng)建Web站點(diǎn)的實(shí)現(xiàn)7. 如何在Python項(xiàng)目中引入日志8. .net如何優(yōu)雅的使用EFCore實(shí)例詳解9. 通過(guò)CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫(huà)特效10. python b站視頻下載的五種版本
