I have the rich:calendar element in a facelet:
<rich:calendar value="#{listBean.to}"
popup="true"
datePattern="d/M/yy"
cellWidth="24px" cellHeight="22px" style="width:200px"/>
where listBean's defined as follows:
#ManagedBean
#SessionScoped
public class ListBean {
private Date to;
//GET, SET, Others
}
and I need to convert the date, picked up by user to the end of a day date. I can convert it in Java as follows:
Calendar date = new GregorianCalendar();
date.set(Calendar.HOUR_OF_DAY, 23);
date.set(Calendar.MINUTE, 59);
date.set(Calendar.SECOND, 59);
date.set(Calendar.MILLISECOND, 999);
to = date.getTime();
But I would not like to write those lines of code and would like to move this convertion in the facelet. Is it possible?
Related
I have a scenario where user selects a start date and end date and user also selects a specific day I need to show that specific day with date that occurs between them.
I tried the Intl package difference method but did not work
You can use this method. Takes the start and end date and also the weekday. Note, can pass in 3 as an int or 'DateTime.wednesday' as the argument.
Note, idea based on mirkancal's answer in this thread
List<DateTime> getAllDatesOfAWeekday(
{required DateTime startDate,
required DateTime endDate,
required int weekday}) {
List<DateTime> allDates = [];
for (int i = 0; i <= endDate.difference(startDate).inDays; i++) {
if (startDate.add(Duration(days: i)).weekday == weekday) {
allDates.add(startDate.add(Duration(days: i)));
}
}
return allDates;
}
Guys. I want to write a simple code to add X weeks to a chosen Date but I just can't figure out how. I always get a ton of errors. The function should basically return the chosen date plus "addedweeks" in the format "dd-MM-yyyy". Below is my last attempt. Thanks in advance!
import 'dart:math' as math;
String? addXWeeks(
DateTime? datum,
int? addedweeks,
) {
// add 2 weeks
DateTime date = datum.toLocal;
date = DateTime(date.year, date.month, date.day + (addedweeks*7));
}
this is very easy. DateTime has a method called add. You only need to add 7 days, because duration has not the propertie "weeks".
Here is a samle:
void main() {
// Current date
DateTime date = DateTime.now();
// Weeks you want to add
int weeksToAdd = 10;
print("Before: $date");
// Multiply 7 (days a week) with your week and set int to and int
date = date.add(Duration(days: (7 * weeksToAdd).toInt()));
print("After: $date");
// Format date
print("Format date: ${date.day}.${date.month}.${date.year}");
}
The output:
Before: 2022-10-06 13:23:16.342888
After: 2022-12-15 12:23:16.342888
Format date: 15.12.2022
I am trying to use a PageView.builder in my application and i wanted each page to display a particular date. I have defined a list of type DateTime : List<DateTime> _month;. how do i store all the days in a particular month (30 days) in the list _month?
The stored dates must be of type DateTime in order to implement this in my application.
This code will do what you need. I don't know the entire structure of your code so I just wrote this example!
void main() {
int month = 1;
DateTime start = DateTime(2019,month);
DateTime end = DateTime(2019,month+1);
int c = (end.toUtc().difference(start.toUtc()).inDays);
List<DateTime> _month = [];
_month.addAll(List.generate(c,(index) => start.toUtc().add(Duration(days:index)).toLocal()));
print(_month);
}
I have 2 tables, Timesheet_Head and Timesheet_Detail.
Timesheet_Head fields :
TimesheetID
Month
Year
Timesheet_Detail fields:
TimesheetID
ActivityDate
ActivityDesc
i want to show some records generated by month and year fields, from first day until last day of the month when action button clicked, for example:
No. date Description
1. 2/1/2016
2. 2/2/2016
3. 2/3/2016
4. 2/4/2016
... ...
29. 2/29/2016
does anyone have any ideas? Thanks in advance.
As I understand you are trying to achieve something like that:
expected behavior
So the action 'Generate' will look something like that:
public PXAction<Filter> generate;
[PXUIField(DisplayName = "Generate", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Visible = true)]
[PXButton()]
public virtual IEnumerable Generate(PXAdapter adapter)
{
Filter filter= TranFilter.Current;
if(filter==null || filter.Year==null)
return adapter.Get();
FinYear year = PXSelect<FinYear, Where<FinYear.year, Equal<Required<FinYear.year>>>>.Select(this, filter.Year);
for (DateTime date = year.StartDate ?? DateTime.Now; date < year.EndDate; date = date.AddDays(1))
{
Detail row = new Detail();
row.Date = date;
Details.Insert(row);
}
return adapter.Get();
}
If you want to use a year actually but not a financial year I guess you should use .Net DateTime class to get first and last date of the period.
The Calendar clicked signal returns a date as follows:
2015-11-13T00:00:00
However, I would like to have a date formatted like this:
Fri Nov 13 2015
This is what I tried:
onSelectedDateChanged:
{
calender.visible = false;
selectedDate = selectedDate.toLocaleTimeString(Qt.LocalDate, Locale.ShortFormat);
textOfSelectedDate.text = Date.fromLocaleTimeString(Qt.LocalDate, selectedDate, Locale.ShortFormat)}
}
textOfSelectedDate is the id of the text box where this date will be displayed.
How can I extract day, month, and year in a desired format from Date returned by Calender?
QML's date type extends Javascript's Date. Thus you can do:
onSelectedDateChanged: {
const day = selectedDate.getDate();
const month = selectedDate.getMonth() + 1; //assuming you want 1..12, getMonth()'s return value is zero-based!
const year = selectedDate.getFullYear();
...
}
First of all, date is similar to JS date type. So you can use all its functions, like getDate() etc. See it here
Also, you can use Qt.formatDate() object to format the result. In your case it can be as follows:
onClicked: {
console.log(Qt.formatDate(date,"ddd MMM d yyyy"))
}