Convert a local time to a specific country time with JodaTime





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am having problem trying to figure out how to convert a person's local time to a UK time with Joda.
Say,
31-01-2015 12:00:01am Washington DC time(could be any country's time) to



31-01-2015 5:00:01am london time(London time should always be the output)



DateTimeZone zone = DateTimeZone.forID("Europe/London"); DateTime dt = new DateTime(zone);


Can't seem to format that into this format
Day-Month-Year hour:min:sec:a










share|improve this question























  • hope this will be helpful: codereview.stackexchange.com/a/18812/130743

    – dkb
    Jan 3 at 6:17


















1















I am having problem trying to figure out how to convert a person's local time to a UK time with Joda.
Say,
31-01-2015 12:00:01am Washington DC time(could be any country's time) to



31-01-2015 5:00:01am london time(London time should always be the output)



DateTimeZone zone = DateTimeZone.forID("Europe/London"); DateTime dt = new DateTime(zone);


Can't seem to format that into this format
Day-Month-Year hour:min:sec:a










share|improve this question























  • hope this will be helpful: codereview.stackexchange.com/a/18812/130743

    – dkb
    Jan 3 at 6:17














1












1








1


0






I am having problem trying to figure out how to convert a person's local time to a UK time with Joda.
Say,
31-01-2015 12:00:01am Washington DC time(could be any country's time) to



31-01-2015 5:00:01am london time(London time should always be the output)



DateTimeZone zone = DateTimeZone.forID("Europe/London"); DateTime dt = new DateTime(zone);


Can't seem to format that into this format
Day-Month-Year hour:min:sec:a










share|improve this question














I am having problem trying to figure out how to convert a person's local time to a UK time with Joda.
Say,
31-01-2015 12:00:01am Washington DC time(could be any country's time) to



31-01-2015 5:00:01am london time(London time should always be the output)



DateTimeZone zone = DateTimeZone.forID("Europe/London"); DateTime dt = new DateTime(zone);


Can't seem to format that into this format
Day-Month-Year hour:min:sec:a







java jodatime android-jodatime






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 2:53









aloyaloy

164




164













  • hope this will be helpful: codereview.stackexchange.com/a/18812/130743

    – dkb
    Jan 3 at 6:17



















  • hope this will be helpful: codereview.stackexchange.com/a/18812/130743

    – dkb
    Jan 3 at 6:17

















hope this will be helpful: codereview.stackexchange.com/a/18812/130743

– dkb
Jan 3 at 6:17





hope this will be helpful: codereview.stackexchange.com/a/18812/130743

– dkb
Jan 3 at 6:17












1 Answer
1






active

oldest

votes


















1














The input format is in Washington DC time and output is in London time
You can have multiple zone id as input and output.
Get timezone ids from here



import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class Test {

public static void main(String args) throws Exception {

final DateTimeZone fromTimeZone = DateTimeZone.forID("EST");
final DateTime dateTime = new DateTime("2019-01-03T01:25:00", fromTimeZone);

final org.joda.time.format.DateTimeFormatter outputFormatter
= DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss a").withZone(DateTimeZone.forID("Europe/London"));
System.out.println("London time":outputFormatter.print(dateTime));

}


output:




2019-01-03 06:25:00 AM




Ref






share|improve this answer
























  • Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

    – aloy
    Jan 3 at 18:14













  • You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

    – dkb
    Jan 4 at 5:33












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015733%2fconvert-a-local-time-to-a-specific-country-time-with-jodatime%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The input format is in Washington DC time and output is in London time
You can have multiple zone id as input and output.
Get timezone ids from here



import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class Test {

public static void main(String args) throws Exception {

final DateTimeZone fromTimeZone = DateTimeZone.forID("EST");
final DateTime dateTime = new DateTime("2019-01-03T01:25:00", fromTimeZone);

final org.joda.time.format.DateTimeFormatter outputFormatter
= DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss a").withZone(DateTimeZone.forID("Europe/London"));
System.out.println("London time":outputFormatter.print(dateTime));

}


output:




2019-01-03 06:25:00 AM




Ref






share|improve this answer
























  • Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

    – aloy
    Jan 3 at 18:14













  • You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

    – dkb
    Jan 4 at 5:33
















1














The input format is in Washington DC time and output is in London time
You can have multiple zone id as input and output.
Get timezone ids from here



import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class Test {

public static void main(String args) throws Exception {

final DateTimeZone fromTimeZone = DateTimeZone.forID("EST");
final DateTime dateTime = new DateTime("2019-01-03T01:25:00", fromTimeZone);

final org.joda.time.format.DateTimeFormatter outputFormatter
= DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss a").withZone(DateTimeZone.forID("Europe/London"));
System.out.println("London time":outputFormatter.print(dateTime));

}


output:




2019-01-03 06:25:00 AM




Ref






share|improve this answer
























  • Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

    – aloy
    Jan 3 at 18:14













  • You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

    – dkb
    Jan 4 at 5:33














1












1








1







The input format is in Washington DC time and output is in London time
You can have multiple zone id as input and output.
Get timezone ids from here



import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class Test {

public static void main(String args) throws Exception {

final DateTimeZone fromTimeZone = DateTimeZone.forID("EST");
final DateTime dateTime = new DateTime("2019-01-03T01:25:00", fromTimeZone);

final org.joda.time.format.DateTimeFormatter outputFormatter
= DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss a").withZone(DateTimeZone.forID("Europe/London"));
System.out.println("London time":outputFormatter.print(dateTime));

}


output:




2019-01-03 06:25:00 AM




Ref






share|improve this answer













The input format is in Washington DC time and output is in London time
You can have multiple zone id as input and output.
Get timezone ids from here



import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class Test {

public static void main(String args) throws Exception {

final DateTimeZone fromTimeZone = DateTimeZone.forID("EST");
final DateTime dateTime = new DateTime("2019-01-03T01:25:00", fromTimeZone);

final org.joda.time.format.DateTimeFormatter outputFormatter
= DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss a").withZone(DateTimeZone.forID("Europe/London"));
System.out.println("London time":outputFormatter.print(dateTime));

}


output:




2019-01-03 06:25:00 AM




Ref







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 6:29









dkbdkb

1,67411726




1,67411726













  • Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

    – aloy
    Jan 3 at 18:14













  • You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

    – dkb
    Jan 4 at 5:33



















  • Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

    – aloy
    Jan 3 at 18:14













  • You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

    – dkb
    Jan 4 at 5:33

















Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

– aloy
Jan 3 at 18:14







Thanks, but I need to convert from any time zone to London time. Not just from Washington DC time. Like uhm, get the current time using DateTime() or Date() then to London time. Pls add more comments on where I can change from the code. Thanks.

– aloy
Jan 3 at 18:14















You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

– dkb
Jan 4 at 5:33





You can put zone id in the place of "EST" in fromTimeZone variable, that's it.

– dkb
Jan 4 at 5:33




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015733%2fconvert-a-local-time-to-a-specific-country-time-with-jodatime%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory