Java's specific code for converting time into unix timestamp is for your reference. The specific content is as follows
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; /** * @author kongqz [email protected] * @version Created time: 2013-2-19 10:21:47 am */ public class TestUnixTime { public static void main(String[] args) throws ParseException{ DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //1361325960 long epoch = df.parse("2013-02-20 10:06:00").getTime(); System.out.println("should be 1361325960 :"+epoch); Date d=new Date(); String t=df.format(d); epoch=df.parse(t).getTime()/1000; System.out.println("t is : "+t+",unix stamp is "+epoch); } }
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.