How to get date values in month, year and days in grails datePicker
<g:datePicker id="test" name="test" precision="day"></g:datePicker >
I tried using getDate() but I do not get any value.
Try this approach, first register change handler to each of the 3 selects generated by the datePicker tag, then call the dateWasChanged method and inside that build your date and update your mydate div.
Note: On date Object month is 0 base (index) so you need to deduct 1 unit from the actual select value.
<body>
<g:datePicker id="test" name="test" precision="day"></g:datePicker >
<div id="mydate"></div>
<script type="text/javascript" charset="utf-8">
dateWasChanged()
$( "#test_day" ).change(function() {
dateWasChanged();
});
$( "#test_month" ).change(function() {
dateWasChanged();
});
$( "#test_year" ).change(function() {
dateWasChanged();
});
function dateWasChanged(){
var year = $( "#test_year" ).val();
var month = $( "#test_month" ).val()-1;
var day = $( "#test_day" ).val();
var date = new Date(year,month,day);
$("#mydate").text(date.toString())
}
</script>
</body>
Try something like the following:
Date myDate = params.date('test', 'dd-MM-yyyy')
That will give you a good ol' fashioned java.util.Date object with Groovy extensions that you can use from there. Be sure to set the format (in my case 'dd-MM-yyyy') to whatever date format you are using.
Related
I'm working on an Angular 2 form. I'm getting problems working with a date variable.
For cross-browser compatibility on a calendar input, I'm using ng-pick-datetime (https://www.npmjs.com/package/ng-pick-datetime).
I get this error -> ERROR TypeError: [object Number] is not an instance of Date
The template code of the date input:
<div class="input-control col-sm-6" >
<label class="control-label" for="startDate">
Starting date *
</label>
<owl-date-time
[(ngModel)]="data.startDate"
[dateFormat]="'DD-MM-YYYY'"
[inputId]="'startDate'"
[placeHolder]="'dd-mm-aaaa'"
[type]="'calendar'"
[dataType]="'date'"
[autoClose]="'true'"
id="startDate"
name="startDate"
#startDate="ngModel"
[disabled]="!paramsService.isSolicitante()"
[hideClearButton]="!paramsService.isSolicitante()"
[max]="data.endDate"
required>
</owl-date-time >
</div>
The declaration of this startDate property in the typescript "Data" class:
startDate: Date = new Date();
endDate: Date = null;
As you can see, the [dataType] property on the calendar picker is set to 'date', same type as the variable.
What am I doing wrong?
Solved! It was an issue of assigning the data from one variable to another, with no use of new Date().
I'm new to aem. I'm trying to implement the following example in aem by using sightly. currently im working on aem 6.1.
can you please guide me how can i access current time in sightly.
I'm using dialog boxes to show greeting messages according to current time.
<div data-sly-use.clientlibInclude="${'/libs/granite/sightly/templates/clientlib.html'}"></div>
<output data-sly-call="${clientlibInclude.css # categories='angular-global-category'}" data-sly-unwrap />
<html> `enter code here`
<head>
<title>Greeting Message using JavaScript</title>
</head>
<body>
<section class="intro">
<h1> <label id="lblGreetings"></label></h1></section>
</body>
<script>
var myDate = new Date();
var hrs = myDate.getHours();
var greet;
if (hrs < 12)
greet = 'Good Morning';
else if (hrs >= 12 && hrs <= 17)
greet = 'Good Afternoon';
else if (hrs >= 17 && hrs <= 24)
greet = 'Good Evening';
document.getElementById('lblGreetings').innerHTML =
'' + greet + ' Julio';
</script>
</html>
There's no native objects that contain server date information in sightly. To print a date with sightly you need to have a Model related to it and use it within sightly. You can have a javascript model or a java one.
quick js guide found on the net: http://blogs.adobe.com/experiencedelivers/experience-management/htl-javascript-use-api/
If you'd want to go with Java I'd advise using SlingModels or Slice for modelling.
Seems to me you didn't do much reading on sighlty. Please read the docs first.
Actually you can create a java.util.Date as a model:
<sly data-sly-use.time="java.util.Date">${time.hours}</sly>
But that's just for fun or debugging, and not good style - I think it's much better do move such logic into a model, Java or otherwise. (And this just uses the default timezone...)
I am trying to create a moment object from string which contains date in format DD/MM/YYYY. I want to set this to be DD/MM/YYYY 23:30. For this, I am writing the code as
moment.utc('30/04/2016','DD/MM/YYYY').hours(23).minutes(30)
However, that for some reason sets the milliseconds to 300. I am unable to set milliseconds to 0 even using the code below
moment.utc('30/04/2016','DD/MM/YYYY').hours(23).minutes(30).milliseconds(0)
I only need my date to be like 30/04/2016 23:30:00 and not like 30/04/2016 23:30:00:300
Please see JS Fiddle
Why is the millisecond part being set to 300 and if why am I not able to set it to 0?
Use this
moment.utc('30/04/2016 23:30:00 0','DD/MM/YYYY HH:mm:ss SSS')
See this http://momentjs.com/docs/#/parsing/string-format/ & http://momentjs.com/docs/#/displaying/
Try this,
<body>
<p>Click the button to display date</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var d = new Date();
var n=moment.utc('30/04/2016','DD/MM/YYYY').hours(23).minutes(30).seconds(0).milliseconds(0).format('DD/MM/YYYY hh:mm:ss.SSS');
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
working fiddler,
http://jsfiddle.net/fhdd8/356/
Well u can set time according to your choice by default .now() add upto millisecond.
var datetime = moment().set({ hour: 10, minute: 22, second : 19 , millisecond : 999 });
var datetime2 = moment().hour(23).minute(2).second(20);
var time3 = moment('23:11:22.322', "LTS.SSS", true);
datetime.format(LTS.SSS);
datetime2.format(LTS);
datetime.format("hh:mm:ss.SSS")
LTS - Localized formats
Time LT 8:30 PM
Time with seconds LTS 8:30:25 PM
SSS - Milisecond*s
For display use format()
I am using liferay-ui datepicker.
When my page loads the date is current date in the datepicker and data of the current date is loaded on the page.
What I want to do is allow the user to view data such that when user selects any other date, data of the selected date is dispayed.
How should I go about this?
SHould I refresh the entire page? how?
Or should I use ajax? how should i go about? if ajax is to be used how should i pass the data?
EDIT:
I will explain my problem in detail. I am using liferay:ui:date . I want user to select a date from it. Once the user selects date, I want to pass the date to custom-sql. I am calling the finder function in the same jsp as follows:
List<Object[]> ObjdisplayAttListName = AttendanceLocalServiceUtil.findAttendance(currentdate);
I want to pass the user selected date in the above function.
Right now what I am doing is only passing the current date in the above line of code. Iwant to pass the user selected date.
I think you should go with AJAX. Make ajax call when you select date using date-picker
and get that date in your serveResource method. Based on your selected date fetch data and pass that data to your presentation layer in required format i.e JSON.
Collect data and display it. Thats it :)
Let me know if you have problem !!
Personally, I prefer working with liferay-ui:input-date. Just make sure to keep a Date or Calendar object in your Controller Class
<portlet:actionURL var="setDate" name="setDate" >
<portlet:param name="jspPage" value="/html/yourPage.jsp" />
</portlet:actionURL>
<aui:form action="<%= setDate%>" method="post" enctype="multipart/form-data" >
<%
Date date = (Date)renderRequest.getAttribute("_a_date");// Get your Date from the controller
Calendar cal = CalendarFactoryUtil.getCalendar();
cal.setTime(new Date()); // create with current date if this form is presented for the 1st time
if(Validator.isNotNull(date)){
cal.setTime(date); // else use the Date you want to display
}
%>
<liferay-ui:input-date
yearRangeStart="1970"
yearRangeEnd="2100"
formName="pickedDate"
dayParam="dd"
monthParam="mm"
yearParam="yy"
dayValue="<%= cal.get(Calendar.DATE) %>"
monthValue="<%= cal.get(Calendar.MONTH) %>"
yearValue="<%= cal.get(Calendar.YEAR) %>"
/>
<aui:button name="setDateBtn" value="Submit that date" type="submit"/>
</aui:form>
Back to the controller..
public void setDate(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
UploadPortletRequest queryRequest = PortalUtil.getUploadPortletRequest(actionRequest);
int dd = ParamUtil.getInteger(queryRequest, "dd");
int mm = ParamUtil.getInteger(queryRequest, "mm");
int yy = ParamUtil.getInteger(queryRequest, "yy");
String date_format = "yyyy/MM/dd";
SimpleDateFormat sdf = new SimpleDateFormat(date_format);
GregorianCalendar gc = new GregorianCalendar(yy, mm, dd);
Date date = gc.getTime(); // Keep this Date and reload the page sending this Date in an actionRequest param
actionRequest.setAttribute("_a_date", date );
I have a Sharepoint data entry Form for my List (Inspection Table), which has a field called "Date Entered". I want to automatically populate today's date and time when a user clicks on "Add new entry", as I want to use that as audit data.
Now, I wanted to use java script (as after research, this seems the most straight forward way to do so), so I added the following to the NewForm.aspx page:
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<script language="javascript" type="text/javascript">
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10)
{dd='0'+dd;}
if(mm<10)
{mm='0'+mm;}
var formattedToday = mm+'/'+dd+'/'+yyyy;
alert(formattedToday);
document.getElementById('<%= ((TextBox)this.onetIDListForm.FindControl("ff10_1")).ClientID %>').value = formattedToday;
</script>
</asp:Content>
The alert(formattedToday); is just to test if the java script is picked up of course and will be removed in later stage.
Ok.. I get the popup, so the value is calculated correctly and java script works. The problem I have, is putting this value to the "Date Entered" field.
What would be the correct method to call the document.getElementByID?
I have tried multiple variations:
document.getElementById('<%= ((TextBox)this.onetIDListForm.FindControl("ff10_1")).ClientID %>').value = formattedToday;
Or..
document.setElementById("Date Entered").value = formattedToday;
Or..
document.setElementById("ff10_1").value = formattedToday;
Can somebody point me to the correct format, or the way to make this work?
Next to the script above, I think I need the Form field "Date Entered" behavior (enable view) to be set to "False" but that is out of scope at the moment.
Thanks,
Chris
Take a look at this article. It talks about how you can achieve this using jQuery. See sample below and try it out. You will have replace the column name with your corresponding name "Date Entered". This should populate the appropriate textbox for you.
<script type="text/javascript">
$(function() {
$('input[title=DefaultMeFieldNoSpaces]').attr(
{value: 'You are in a twisty maze of passages, all alike.'});
});