Create file name using date and time

后端 未结 5 1838
清酒与你
清酒与你 2020-12-14 00:31

I hope you could help me, I\'m trying to call in the date from another class and looks like \"2011-03-09 06-57-40\", I want to use this to create the file below but everytim

5条回答
  •  长情又很酷
    2020-12-14 01:08

    public class BELogs {
    
        private final static Logger logger = Logger.getLogger(BSELogs.class
                .getName()); 
    
                 boolean makeDir = false;
                 Date date = new Date();
                 SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy") ;
                 String curDate =dateFormat.format(date);
                 FileHandler fh;     
    
                   public BSELogs()  {
    
             try {  
    
                 File file = new File("/home//Desktop/Logs "+curDate);
                 makeDir = file.mkdir();
                 fh = new FileHandler(file+"/MyLogFile.log "+curDate,true);  
                 logger.addHandler(fh);
                 // Set the logger level to produce logs at this level and above.
                 logger.setLevel(Level.FINE);
                 SimpleFormatter formatter = new SimpleFormatter();  
                 fh.setFormatter(formatter);  
    
              } catch (SecurityException ex) {  **strong text**
                 ex.printStackTrace();  
              } catch (IOException e) {  
                   e.printStackTrace();  
               }  
    
        logger.info("Data Log Genrated............"); 
    
          }
    }             
    

提交回复
热议问题