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;
}
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
add a comment |
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
hope this will be helpful: codereview.stackexchange.com/a/18812/130743
– dkb
Jan 3 at 6:17
add a comment |
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
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
java jodatime android-jodatime
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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" infromTimeZone
variable, that's it.
– dkb
Jan 4 at 5:33
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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" infromTimeZone
variable, that's it.
– dkb
Jan 4 at 5:33
add a comment |
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
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" infromTimeZone
variable, that's it.
– dkb
Jan 4 at 5:33
add a comment |
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
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
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" infromTimeZone
variable, that's it.
– dkb
Jan 4 at 5:33
add a comment |
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" infromTimeZone
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
hope this will be helpful: codereview.stackexchange.com/a/18812/130743
– dkb
Jan 3 at 6:17