This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to convert Data to Unix_Timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert Data to Unix_Timestamp" Watch "How to convert Data to Unix_Timestamp" New topic
Author

How to convert Data to Unix_Timestamp

Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
Hi,

I want to convert date to unix_timestamp. Suppose if i give 11-June-07 as input, i want to get 1181648109265 as output. How should i do it?

What i am doing right now is:



What changes should i make to get required output?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You already use that value, with date.getTime().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
date.getTime() gives -61932556800000 value, when i am storing in Long variable. It's different from expected value.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Your input is incorrect. The 07 means the year 0007. Either change the input to "11-June-2007", or change the pattern to "dd-MM-yy".
Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
I changed the input (although that too is correct). still same error
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Please post your full new code. Because when I tried changing either the input or the pattern I got the desired result.
Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
oh! My Bad. Sorry.. It's working now. Thanks a lot
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You're welcome.
 
GeeCON Prague 2014
 
subject: How to convert Data to Unix_Timestamp