Question

Hi there how to show allow ui date picker for time field using 24 hours format? I'f I'm using

[code]

<%
            Calendar dob = CalendarFactoryUtil.getCalendar();
        dob.setTime(new Date());
        %>

        <aui:input name="schedule_msg" model="<%= Message_Schedule.class %>"
        bean="<%= msch %>" value="<%= now %>" label="Schedule Time"/>



[/code]

it shows in am/PM mode...or if using AM/PM mode how to get the value??normally if i want to get value in my Portlet Class just like this [code]

int day = ParamUtil.getInteger(request, "schedule_msgDay");
        int month = ParamUtil.getInteger(request, "schedule_msgMonth");
        int year = ParamUtil.getInteger(request, "schedule_msgYear");
        int hour = ParamUtil.getInteger(request, "schedule_msgHour");
        int min  = ParamUtil.getInteger(request, "schedule_msgMinute");

        try
        {

            msgSchedule.setSchedule_msg(PortalUtil.getDate(month, day, year, hour, min, new PortalException()));
        }catch(Exception e)
        {
            msgSchedule.setSchedule_msg(new Date());
        }

[/code] any idea how to get that value?? example in the picture it show 4:54: PM so it means in 24 hours it become 16:54:00 .... Please any help

Thank's

Regards

Danial

Était-ce utile?

La solution

The aui:input taglib (which in turn uses the liferay-ui:input-date and liferay-ui:input-time taglibs) shows the AM/PM select box if the time format for the current locale requires it. In Liferay 6.1.1, have a look at row 36 in html/taglib/ui/input_time/page.jsp.

So you should definitely keep the built-in behavior, which shows the AM/PM select box depending on the current locale.

In order to get the date properly in your portlet class, you can draw inspiration from the EditEventAction class, which is the Struts action called when you add, update or delete an event in the Calendar portlet. Something like this:

int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth");
int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay");
int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear");
int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour");
int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute");
int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm");

if (startDateAmPm == Calendar.PM) {
    startDateHour += 12;
}

After that, if you want to get a Date object from these values, it's important to decide whether these values represent a date in UTC, in the current user's timezone or whatever. Have a look at the addEvent method in CalEventLocalServiceImpl class to know how to do it: basically, you have to create a Calendar object with the CalendarFactoryUtil.getCalendar method, passing a locale and a timezone, and then you can set the various values.

Autres conseils

Liferay UI part is poorly documented, here is the attributes I found, http://docs.liferay.com/portal/6.2/taglibs/liferay-ui/input-time.html, but it never describe how to use these attributes, what are the values of these attributes.

I wasted too much time on googling and experimenting, and I decided to use JQuery datetime pick instead.

Another way is don't use liferay-ui:input-time, just to use your own hours and mins select input.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top