java 格式化時間的示例代碼
更新時間:2020年12月10日 11:56:54 作者:小白龍白龍馬
這篇文章主要介紹了java 格式化時間的示例代碼,幫助大家更好的利用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 Firefox\\firefox.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)注腳本之家其它相關(guān)文章!
相關(guān)文章
Spring boot route Controller接收參數(shù)常用方法解析
這篇文章主要介紹了Spring boot route Controller接收參數(shù)常用方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-10-10
Java設(shè)計模式之外觀模式(Facade模式)介紹
這篇文章主要介紹了Java設(shè)計模式之外觀模式(Facade模式)介紹,外觀模式(Facade)的定義:為子系統(tǒng)中的一組接口提供一個一致的界面,需要的朋友可以參考下2015-03-03
SpringCloud集成Micrometer Tracing的代碼工程
Micrometer Tracing 是一個用于微服務(wù)架構(gòu)的追蹤庫,它提供了一種簡單而強(qiáng)大的方式來收集和報告分布式系統(tǒng)中的性能和調(diào)用鏈信息,Micrometer Tracing 旨在幫助開發(fā)者和運(yùn)維人員理解微服務(wù)之間的交互,本文給大家介紹了如何在 Spring Cloud 集成 Micrometer Tracing2024-12-12
解析Mybatis的insert方法返回數(shù)字-2147482646的解決
這篇文章主要介紹了解析Mybatis的insert方法返回數(shù)字-2147482646的解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
IntelliJ IDEA中顯示和關(guān)閉工具欄與目錄欄的方法
今天小編就為大家分享一篇關(guān)于IntelliJ IDEA中顯示和關(guān)閉工具欄與目錄欄的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10

