Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This comment may be part of the problem:</p> <pre><code>//time in UTC standard DateTime processingDate = DateTime.now(); </code></pre> <p>No, <code>DateTime.now()</code> returns the current time in the default time zone. So when you later use <code>withZone(DateTimeZone.getDefault())</code> that's a no-op.</p> <p>However, I'd still have expected <code>fmtHour.withZone(DateTimeZone.UTC).print(processingDate)</code> to convert to UTC.</p> <p>Indeed, that's what I get when I manually set the default time zone to something other than UTC:</p> <pre><code>import org.joda.time.*; import org.joda.time.format.*; public class Test { public static void main(String[] args) { DateTimeZone pacific = DateTimeZone.forID("America/Los_Angeles"); DateTimeZone.setDefault(pacific); DateTime processingDate = DateTime.now(); //local time LocalDateTime localDateTime = processingDate. withZone(DateTimeZone.getDefault()).toLocalDateTime(); DateTimeFormatter fmtDate = DateTimeFormat.forPattern("dd/MM/yyyy"); DateTimeFormatter fmtHour = DateTimeFormat.forPattern("HH:mm:ss"); System.out.println("Date: " + fmtDate.print(processingDate)); System.out.println("Time: " + fmtHour.withZone(DateTimeZone.UTC). print(processingDate)); System.out.println("Local date: " + fmtDate.print(localDateTime)); System.out.println("Local time: " + fmtHour.print(localDateTime)); } } </code></pre> <p>Output:</p> <pre><code>Date: 06/12/2012 Time: 13:19:35 Local date: 06/12/2012 Local time: 05:19:35 </code></pre> <p>Are you sure the problem isn't just that your default time zone <em>is</em> UTC?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload