Convert UTC timestamp to local timestampAndroid get Current UTC timeGet date in current timezone in javaHow to convert a Drawable to a Bitmap?Converting pixels to dpCalendar getTimeInMillis() is timezone-dependent?Converting UTC timestamp to local device timestampandroid sqlite save and retrieve utc and convert to localHow to get another Calendar result from same instance?new Date() returns local time instead of UTCManually Set System Clock Screws Up UTC in Android and IOSHow to get 2 date objects holding the current time, one in GMT and the other in localConvert hour minute string time to utc and vice versa

Did the CIA blow up a Siberian pipeline in 1982?

What is the origin of Scooby-Doo's name?

What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?

What are the pros and cons for the two possible "gear directions" when parking the car on a hill?

Story about a space war, and a human prisoner of war captured by alien enemy

How to make clear to people I don't want to answer their "Where are you from?" question?

Excluding a rectangular region from an image in FITS

What can I do with a research project that is my university’s intellectual property?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

Prime sieve in Python

Intuition for the role of diffeomorphisms

Heavily limited premature compiler translates text into excecutable python code

Is it possible to get a mortgage with a custom duration in the US?

Constitutionality of U.S. Democratic Presidential Candidate's Supreme Court Suggestion

Why is it recommended to mix yogurt starter with a small amount of milk before adding to the entire batch?

Can Ogre clerics use Purify Food and Drink on humanoid characters?

Hit the Bulls Eye with T in the Center

Why is "Congress shall have power to enforce this article by appropriate legislation" necessary?

Is declining an undergraduate award which causes me discomfort appropriate?

What do they call philosophers in China?

Is there any proof that high saturation and contrast makes a picture more appealing in social media?

Count All Possible Unique Combinations of Letters in a Word

Why don't countries like Japan just print more money?

"Permanent resident of UK” for a British travel insurance in the US



Convert UTC timestamp to local timestamp


Android get Current UTC timeGet date in current timezone in javaHow to convert a Drawable to a Bitmap?Converting pixels to dpCalendar getTimeInMillis() is timezone-dependent?Converting UTC timestamp to local device timestampandroid sqlite save and retrieve utc and convert to localHow to get another Calendar result from same instance?new Date() returns local time instead of UTCManually Set System Clock Screws Up UTC in Android and IOSHow to get 2 date objects holding the current time, one in GMT and the other in localConvert hour minute string time to utc and vice versa






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








0















I want to get the local time in millseconds from UTC milliseconds... I tried following code.. But it return same UTC time instead of local time.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(aLong);
Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
calendar1.setTimeInMillis(calendar.getTimeInMillis());
return calendar1.getTimeInMillis();



Actually I don't want DateFormat String, I need milliseconds back... That's why I used Calendar instance.










share|improve this question
























  • stackoverflow.com/a/24808474/1042124

    – Rahul Kumar
    Mar 25 at 7:48











  • Possible duplicate of Android get Current UTC time

    – ADM
    Mar 25 at 7:50











  • @RahulKumar I have edited my question as I need milliseconds only back.

    – Gunaseelan
    Mar 25 at 8:02

















0















I want to get the local time in millseconds from UTC milliseconds... I tried following code.. But it return same UTC time instead of local time.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(aLong);
Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
calendar1.setTimeInMillis(calendar.getTimeInMillis());
return calendar1.getTimeInMillis();



Actually I don't want DateFormat String, I need milliseconds back... That's why I used Calendar instance.










share|improve this question
























  • stackoverflow.com/a/24808474/1042124

    – Rahul Kumar
    Mar 25 at 7:48











  • Possible duplicate of Android get Current UTC time

    – ADM
    Mar 25 at 7:50











  • @RahulKumar I have edited my question as I need milliseconds only back.

    – Gunaseelan
    Mar 25 at 8:02













0












0








0








I want to get the local time in millseconds from UTC milliseconds... I tried following code.. But it return same UTC time instead of local time.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(aLong);
Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
calendar1.setTimeInMillis(calendar.getTimeInMillis());
return calendar1.getTimeInMillis();



Actually I don't want DateFormat String, I need milliseconds back... That's why I used Calendar instance.










share|improve this question
















I want to get the local time in millseconds from UTC milliseconds... I tried following code.. But it return same UTC time instead of local time.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(aLong);
Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
calendar1.setTimeInMillis(calendar.getTimeInMillis());
return calendar1.getTimeInMillis();



Actually I don't want DateFormat String, I need milliseconds back... That's why I used Calendar instance.







android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 8:01







Gunaseelan

















asked Mar 25 at 7:36









GunaseelanGunaseelan

7,48294696




7,48294696












  • stackoverflow.com/a/24808474/1042124

    – Rahul Kumar
    Mar 25 at 7:48











  • Possible duplicate of Android get Current UTC time

    – ADM
    Mar 25 at 7:50











  • @RahulKumar I have edited my question as I need milliseconds only back.

    – Gunaseelan
    Mar 25 at 8:02

















  • stackoverflow.com/a/24808474/1042124

    – Rahul Kumar
    Mar 25 at 7:48











  • Possible duplicate of Android get Current UTC time

    – ADM
    Mar 25 at 7:50











  • @RahulKumar I have edited my question as I need milliseconds only back.

    – Gunaseelan
    Mar 25 at 8:02
















stackoverflow.com/a/24808474/1042124

– Rahul Kumar
Mar 25 at 7:48





stackoverflow.com/a/24808474/1042124

– Rahul Kumar
Mar 25 at 7:48













Possible duplicate of Android get Current UTC time

– ADM
Mar 25 at 7:50





Possible duplicate of Android get Current UTC time

– ADM
Mar 25 at 7:50













@RahulKumar I have edited my question as I need milliseconds only back.

– Gunaseelan
Mar 25 at 8:02





@RahulKumar I have edited my question as I need milliseconds only back.

– Gunaseelan
Mar 25 at 8:02












1 Answer
1






active

oldest

votes


















0














The code you wrote creates two Calendars with the same timestamp in two different time zones, so of course the value of getTimeInMillis will be the same. There are three components to a date - the time zone, the milliseconds since epoch, and the date fields - and when you set two of these, the third is derived from them. So what you should be setting in addition to the time zone, is the date fields, so that the milliseconds value can be derived.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(System.currentTimeMillis());

Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
// 7 date fields: YEAR, MONTH, DAY_OF_MONTH,
// HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND
// they come from "import static java.util.Calendar.*;"
calendar1.set(calendar.get(YEAR),
calendar.get(MONTH),
calendar.get(DAY_OF_MONTH),
calendar.get(HOUR_OF_DAY),
calendar.get(MINUTE),
calendar.get(SECOND));
calendar1.set(MILLISECOND, calendar.get(MILLISECOND));
return calendar1.getTimeInMillis();






share|improve this answer























  • 1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

    – Gunaseelan
    Mar 25 at 10:21












  • 1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

    – Leo Aso
    Mar 25 at 12:00











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%2f55333110%2fconvert-utc-timestamp-to-local-timestamp%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









0














The code you wrote creates two Calendars with the same timestamp in two different time zones, so of course the value of getTimeInMillis will be the same. There are three components to a date - the time zone, the milliseconds since epoch, and the date fields - and when you set two of these, the third is derived from them. So what you should be setting in addition to the time zone, is the date fields, so that the milliseconds value can be derived.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(System.currentTimeMillis());

Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
// 7 date fields: YEAR, MONTH, DAY_OF_MONTH,
// HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND
// they come from "import static java.util.Calendar.*;"
calendar1.set(calendar.get(YEAR),
calendar.get(MONTH),
calendar.get(DAY_OF_MONTH),
calendar.get(HOUR_OF_DAY),
calendar.get(MINUTE),
calendar.get(SECOND));
calendar1.set(MILLISECOND, calendar.get(MILLISECOND));
return calendar1.getTimeInMillis();






share|improve this answer























  • 1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

    – Gunaseelan
    Mar 25 at 10:21












  • 1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

    – Leo Aso
    Mar 25 at 12:00















0














The code you wrote creates two Calendars with the same timestamp in two different time zones, so of course the value of getTimeInMillis will be the same. There are three components to a date - the time zone, the milliseconds since epoch, and the date fields - and when you set two of these, the third is derived from them. So what you should be setting in addition to the time zone, is the date fields, so that the milliseconds value can be derived.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(System.currentTimeMillis());

Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
// 7 date fields: YEAR, MONTH, DAY_OF_MONTH,
// HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND
// they come from "import static java.util.Calendar.*;"
calendar1.set(calendar.get(YEAR),
calendar.get(MONTH),
calendar.get(DAY_OF_MONTH),
calendar.get(HOUR_OF_DAY),
calendar.get(MINUTE),
calendar.get(SECOND));
calendar1.set(MILLISECOND, calendar.get(MILLISECOND));
return calendar1.getTimeInMillis();






share|improve this answer























  • 1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

    – Gunaseelan
    Mar 25 at 10:21












  • 1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

    – Leo Aso
    Mar 25 at 12:00













0












0








0







The code you wrote creates two Calendars with the same timestamp in two different time zones, so of course the value of getTimeInMillis will be the same. There are three components to a date - the time zone, the milliseconds since epoch, and the date fields - and when you set two of these, the third is derived from them. So what you should be setting in addition to the time zone, is the date fields, so that the milliseconds value can be derived.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(System.currentTimeMillis());

Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
// 7 date fields: YEAR, MONTH, DAY_OF_MONTH,
// HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND
// they come from "import static java.util.Calendar.*;"
calendar1.set(calendar.get(YEAR),
calendar.get(MONTH),
calendar.get(DAY_OF_MONTH),
calendar.get(HOUR_OF_DAY),
calendar.get(MINUTE),
calendar.get(SECOND));
calendar1.set(MILLISECOND, calendar.get(MILLISECOND));
return calendar1.getTimeInMillis();






share|improve this answer













The code you wrote creates two Calendars with the same timestamp in two different time zones, so of course the value of getTimeInMillis will be the same. There are three components to a date - the time zone, the milliseconds since epoch, and the date fields - and when you set two of these, the third is derived from them. So what you should be setting in addition to the time zone, is the date fields, so that the milliseconds value can be derived.



private long getLocalTimeFromUTC(long aLong) 
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(System.currentTimeMillis());

Calendar calendar1 = Calendar.getInstance(TimeZone.getDefault());
// 7 date fields: YEAR, MONTH, DAY_OF_MONTH,
// HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND
// they come from "import static java.util.Calendar.*;"
calendar1.set(calendar.get(YEAR),
calendar.get(MONTH),
calendar.get(DAY_OF_MONTH),
calendar.get(HOUR_OF_DAY),
calendar.get(MINUTE),
calendar.get(SECOND));
calendar1.set(MILLISECOND, calendar.get(MILLISECOND));
return calendar1.getTimeInMillis();







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 9:28









Leo AsoLeo Aso

5,65311430




5,65311430












  • 1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

    – Gunaseelan
    Mar 25 at 10:21












  • 1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

    – Leo Aso
    Mar 25 at 12:00

















  • 1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

    – Gunaseelan
    Mar 25 at 10:21












  • 1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

    – Leo Aso
    Mar 25 at 12:00
















1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

– Gunaseelan
Mar 25 at 10:21






1553509009000 is my UTC time, When I convert it back using your answer I'm getting 1553489209000. Which is one hour extra.

– Gunaseelan
Mar 25 at 10:21














1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

– Leo Aso
Mar 25 at 12:00





1553489209000 - 1553509009000 is not 1 hour extra, it's 5 and a half hours extra, which is correct if you live in India. Recheck your calculation.

– Leo Aso
Mar 25 at 12:00



















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%2f55333110%2fconvert-utc-timestamp-to-local-timestamp%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현