Take the 2-minute tour ×

there is a form having a drop down for country ,user will select the country ,then there is a drop down for time zone ,user will select the time zone which are available in country selected by the user.Then user will enter the local date( eg: 26-Dec-2014) and time( 23:11)(24 hours time) this entered date and time is for the selected country and time zone. now i have to convert this date and time to GMT time zone. how can i do this using joda time

how the daylight saving time(DST) will be calculate?

i have made a function which accepts the parameters as from time zone,to time zone,date

public static String convertTimeZones( String fromTimeZoneString, 
             String toTimeZoneString, String fromDateTime) {
         DateTimeZone fromTimeZone = DateTimeZone.forID(fromTimeZoneString);
         DateTimeZone toTimeZone = DateTimeZone.forID(toTimeZoneString);
         DateTime dateTime = new DateTime(fromDateTime, fromTimeZone);

         DateTimeFormatter outputFormatter 
            = DateTimeFormat.forPattern("dd-MMM-yyyy HH:mm").withZone(toTimeZone);
        return outputFormatter.print(dateTime);

i want to pass the date to this function in a format (24-Feb-2014 12:34) but it is not taking this format

share|improve this question
Look at this answer. –  Hassan Jan 21 at 12:40
in this link i don't understand any thing, according to my requirement i have to pass the country time zone also which the user has selected –  user2841408 Jan 21 at 13:35
add comment

1 Answer

You can use the class LocalDateTime

LocalDateTime dateTime = new LocalDateTime(time.getTime()); 

and convert the LocalDateTime to DateTime

DateTime dateTime = new LocalDateTime(timestamp.getTime()).toDateTime(DateTimeZone.UTC);  

Joda DateTime treats any time in millis like "millis since 1970y in current time zone". So, when you create DateTime instance, it is created with current time zone.

share|improve this answer
i have made a function but i want to pass a date in a format (eg 24-Feb-2014 12:34) but the function is not taking this format kindly help –  user2841408 Jan 21 at 18:14
add comment

Your Answer


