zoukankan      html  css  js  c++  java
  • java工作复习——格式化时间 ——创建时间命名的文件夹——创建时间命名的截图文件

    package rjcs;
    
    
    
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.awt.*;
    import java.awt.datatransfer.StringSelection;
    import java.awt.event.KeyEvent;
    import java.io.File;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.support.*;
    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;
    
    public class xinkaishi 
    {
    
        
        public static void main(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();
            
             }
        }
        
        
        
    }

    执行结果:

    2020-02-11
    2020-02-11-20-44-54
    20-44-54

  • 相关阅读:
    [LeetCode] 26 Remove Duplicates from Sorted Array
    归并排序
    插入排序
    选择排序
    冒泡排序
    单链表排序
    如何实现单链表反转
    Linux基础——centos 跳过管理员密码进行登录(单用户模式、救援模式)
    response.sendRedirect()与request.getRequestDispatcher().forward()区别
    json-lib——JsonConfig详细使用说明
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12795880.html
Copyright © 2011-2022 走看看