java以时间命名_java工作复习——格式化时间 ——创建时间命名的文件夹——创建时间命名的截图文件...

packagerjcs;importjava.text.DateFormat;importjava.text.SimpleDateFormat;import java.util.*;import java.awt.*;importjava.awt.datatransfer.StringSelection;importjava.awt.event.KeyEvent;importjava.io.File;importorg.apache.commons.io.FileUtils;import org.openqa.selenium.support.*;importorg.openqa.selenium.By;importorg.openqa.selenium.JavascriptExecutor;importorg.openqa.selenium.Keys;importorg.openqa.selenium.OutputType;importorg.openqa.selenium.TakesScreenshot;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.firefox.FirefoxProfile;importorg.openqa.selenium.interactions.Actions;importorg.openqa.selenium.support.ui.Select;public classxinkaishi

{public static voidmain(String[] args)

{

System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置火狐的安装路径,防止系统找不到

FirefoxDriver driver= new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器

try{

driver.manage().window().maximize();//最大化窗口

driver.navigate().to("https://www.baidu.com");

Thread.sleep(5000);

DateFormat dateformat1= new SimpleDateFormat("yyyy-MM-dd"); //创建一个data format对象

Date date1 = new Date(); //利用Date()获取当前时间

String datex = dateformat1.format(date1); //格式化时间,并用String对象存储

System.out.println(datex); //打印格式化时间到控制台

DateFormat dateformat2= new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); //创建一个data format对象

Date date2 = new Date(); //利用Date()获取当前时间

String datey = dateformat2.format(date2); //格式化时间,并用String对象存储

System.out.println(datey); //打印格式化时间到控制台

DateFormat dateformat3= new SimpleDateFormat("HH-mm-ss"); //创建一个data format对象

Date date3 = new Date(); //利用Date()获取当前时间

String dateu = dateformat3.format(date3); //格式化时间,并用String对象存储

System.out.println(dateu); //打印格式化时间到控制台

File src02= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //调用截图方法

FileUtils.copyFile(src02, new File("C:\\Users\\del\\Desktop\\"+datex, dateu + ".png"));

Thread.sleep(5000);

}catch(Exception e)

{

e.printStackTrace();

}finally{

driver.quit();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值