Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,025 questions

51,978 answers

573 users

How to modify a file date and time in Java

1 Answer

0 votes
import java.io.File;
import java.util.Date;
import java.text.SimpleDateFormat;
 
public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            File file = new File("d:\\data.txt");
  
            SimpleDateFormat simpledateformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            System.out.println(simpledateformat.format(file.lastModified())); 
             
            String newdate = "06/18/2013 12:10:31";
            Date date = simpledateformat.parse(newdate);
            file.setLastModified(date.getTime());
            System.out.println(simpledateformat.format(file.lastModified())); 
        }
        catch (Exception e)
        {
            System.out.println(e.toString());
        }  
    }
}


 
/*
 
run:
 
12/31/1999 03:42:17
06/18/2013 12:10:31
 
*/

 



answered Jun 19, 2015 by avibootz
edited Jul 27, 2022 by avibootz

Related questions

1 answer 200 views
1 answer 225 views
225 views asked Jun 18, 2015 by avibootz
1 answer 287 views
1 answer 267 views
2 answers 243 views
2 answers 236 views
236 views asked Jun 15, 2015 by avibootz
...