Set a String date pattern that Javascript must pass. After that, leave it to Java. A slightly more alternative way (if only) to do this would be to use the setTimeZone()
method of DateFormat
as follows:
DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
String strData = "30/05/2014 21:45";
try {
Date data = df.parse(strData);
System.out.println(data);
}
catch (ParseException e) {
e.printStackTrace();
}
The output would be:
Fri May 30 18:45:00 BRT 2014
But you may wonder, what Timezones are available for use in the setTimeZone()
method. You can list all TimeZones as follows:
for (String tz : TimeZone.getAvailableIDs()) {
System.out.println(tz);
}
I will not post the output here, because it is a bit extensive. But I'm sure the timezone you're looking for will be on the list.
EDIT: Complementing the answer regarding Javascript. You can format object Date, using various methods like getMonth()
, getDate()
, getMinutes()
... This way you format the date as you want to send it to Java. See the full reference of the Date object in Javascript.