in Education by
I'm trying to convert a long timestamp that is UTC to Eastern Standard Time and am totally lost. Any hints would be great! Time format should be : 11/4/03 8:14 PM Thanks in advance! TimeZone utcTZ= TimeZone.getTimeZone("UTC"); Calendar utcCal= Calendar.getInstance(utcTZ); utcCal.setTimeInMillis(utcAsLongValue); import java.text.SimpleDateFormat; import java.util.Date; SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz"); sdf.setTimeZone(utcTZ); Date utcDate= utcCal.getTime(); sdf.formatDate(utcDate); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Yesterday occasionally I wrote the following method that can help you: private Date shiftTimeZone(Date date, TimeZone sourceTimeZone, TimeZone targetTimeZone) { Calendar sourceCalendar = Calendar.getInstance(); sourceCalendar.setTime(date); sourceCalendar.setTimeZone(sourceTimeZone); Calendar targetCalendar = Calendar.getInstance(); for (int field : new int[] {Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND}) { targetCalendar.set(field, sourceCalendar.get(field)); } targetCalendar.setTimeZone(targetTimeZone); return targetCalendar.getTime(); } Now you just have to format the date. Use SimpleDateFormat for this. Here is the example: DateFormat format = new SimpleDateFormat("dd/MM/yy hh:mm a"); format.format(date);

Related questions

0 votes
    I'm trying to convert a long timestamp that is UTC to Eastern Standard Time and am totally lost. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Which of the following input control represents a date and time (year, month, day, hour, minute, second, fractions of a second ... - datetime B - datetime-local C - date D - month...
asked Dec 1, 2020 in Technology by JackTerrance
0 votes
    I been receiving date in the "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" format from JSON input, which gets ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I have configured my timezone in settings, as America/Guatemala and I have some datetime fields in my ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I know this questions might seem a little odd, but I want to make sure. One of my superiors is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    Which concept of Java is a way of converting real world objects in terms of class? (a) Polymorphism ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    This question already has answers here: converting date format (5 answers) Closed 5 years ago. I have a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    ______ specializes in converting data from wide to long format. (a) gcc (b) reshape (c) reshape2 (d) ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Which unit is responsible for converting the data received from the user into computer understandable format? Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Consider the developments of India’s Foreign Policy from 1991 till date. Please answer the above question....
asked Aug 18, 2022 in Education by JackTerrance
0 votes
    So I am having trouble with setting the state for the date selected from this DatePicker change: change = ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    So I am having trouble with setting the state for the date selected from this DatePicker change: change = ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    I'm building an application with C# code. How do I get only the date value from a DateTimePicker ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
...