2

I am displaying a date on jsp. Where i am setting the display format of the date as well. i.e (dd.MM.yyyy).

<%
SimpleDateFormat dateFormat = new SimpleDateFormat( "MM-dd-yyyy");
DatePoc myDate= DatePocLocalServiceUtil.fetchDatePoc(1);
%>

<html>
    <div>
        <h1><%=dateFormat.format(myDate.getCreateDate())%></h1>
    </div>
</html>

Now i do not want to set the date format like this, it should be decided by the the user time zone. Suppose if user timezone is US/Canada the date format should be available with (MM.dd.yyyy) and if the user time zone is UK the display date should appear with (dd.MM.yyyy).

Akash
  • 816
  • 3
  • 13
  • 38
  • 1
    Hope this helps you - http://stackoverflow.com/questions/7670355/convert-date-time-for-given-timezone-java – Atul Kumar Sep 27 '16 at 07:19
  • another reference for you [here](http://stackoverflow.com/questions/3001260/how-to-detect-client-timezone) – Imran Sep 27 '16 at 07:21
  • @AtulShrivastava on both of scenario it is printing 'US' only even if i am changing my browser language. Actually I want a differentiate factor to differentiate among both timezone – Akash Sep 27 '16 at 08:36
  • What about UTC−5 for example? Would that mean an english date format or a spanish date format? I'd guess that a mapping from the time zone to the date format is nearly impossible, because often many countries with the same timezone use different formats. – Tobias Liefke Sep 27 '16 at 09:14
  • @Akash Why is this tagged with javascript, liferay, liferay-6? This is clearly about date/time formats based on locales. This maybe: http://stackoverflow.com/questions/1661325/simpledateformat-and-locale-based-format-string – Stefan Keller Sep 27 '16 at 09:24

0 Answers0