ray
ray

Reputation: 4250

android convert Date to TimeStamp

Following code is working fine in my java application. But when I am making the same application for Android using java it's showing error "The constructor Timestamp(long) is undefined" in the following bold line "Timestamp rtnTS = new Timestamp(theDate.getTime());"

public static Timestamp createTimeStamp(String strTime, String strFormat) throws Exception
{
    strTime = strTime.trim();

    SimpleDateFormat formatter = new SimpleDateFormat(strFormat);
    java.util.Date theDate = new java.util.Date();
    theDate = (java.util.Date) formatter.parse(strTime);
    **Timestamp rtnTS = new Timestamp(theDate.getTime());**
    return rtnTS;
}

Anyone please help to sortout this issue.

Upvotes: 1

Views: 7476

Answers (1)

Ajay S
Ajay S

Reputation: 48592

Have you imported these.

import java.sql.Timestamp;
import java.util.Date;

Use like this.

import java.sql.Timestamp;
import java.util.Date;

public class GetCurrentTimeStamp 
{
    public static void main( String[] args )
    {
       java.util.Date date= new java.util.Date();
       Log.v("Time",new Timestamp(date.getTime()));
    }
}

Read from here http://developer.android.com/reference/java/sql/Timestamp.html

Upvotes: 6

Related Questions