wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 19649
    
  18

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: 19649
    
  18

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: 19649
    
  18

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: 19649
    
  18

You're welcome.
 
 
subject: How to convert Data to Unix_Timestamp
 
Similar Threads
convert a string field to date not working as expected.
SQL Column Date Type insertion problem
how to change a date in desired format
string to date conversion
Converting string to date with extra strings