• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Query about lastModified()  RSS feed

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Java.IO.File 's lastModified() method.

As the reur type is long its giving value like this--

1248362044000.

What is the meaning of this?

Is there any way to parse it into simple date format like yyyy-MM-dd hh-mm?


Thanks,
Kaya.
 
Sheriff
Posts: 21555
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, all long values that represent a date/time are the number of milliseconds since the epoch - January 1st 1970 at 00:00:00.

If you need a date, you can use java.util.Date or java.util.Calendar. The first has a constructor that can take such a long, the second has a method called setTimeInMillis.

With those two you don't have any proper formatting though. That's where java.text.DateFormat (and its most popular subclass java.text.SimpleDateFormat) come in. You construct a DateFormat, then pass a Date object to its format method to retrieve a string.
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the API documentation for the method lastModified() in class java.io.File exactly describes what the return value means:

Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs


 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you take a look at java.io.File's API documentation for the lastModified method it says:

API documentation wrote:
Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.



So that's the meaning of the long value returned from this method.

Now if you take a look at the API documentation of the java.util.Date class, you'll notice that in the section about its constructors there's only one overloaded variant that hasn't been deprecated:

API documentation wrote:
public Date(long date)Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Parameters:
date - the milliseconds since January 1, 1970, 00:00:00 GMT.



Edit: Aw crap, too slow...
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob. Now i am able to get my desired result.

Also Thanks to Jelle Klap and Jesper Young for giving me such a nice definition.


 
I am mighty! And this is a mighty small ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!