Reputation: 687
I want to convert currentDate
to TimeStamp.
How can i do that. here is my workings.
//GET UNIX TIME
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT+2"));
String currTime = String.valueOf(c.getTime());
Date requestDate = formatter.parse(currTime);
Calendar requestDateCal = formatter.getCalendar();
requestDateCal.setTime(requestDate);
String currentTime=String.valueOf(requestDateCal.getTimeInMillis());
System.out.println("date : "+ currentTime);
Upvotes: 0
Views: 96
Reputation: 441
First the timestamp is the same for all the time zones, and if you want to print your calendar in other timezone just do this:
formatter.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
Calendar cal = Calendar.getInstance();
System.out.println("date : " + formatter.format(cal.getTime()));
and to get the calendar time zone do this:
cal.getInstance(TimeZone.getTimeZone("Europe/Paris"));
Thanks
Upvotes: 2