Change times of a reservation (timestamp) using Listbox in GWT - date

I want to implement a function (with GWT) to change the start- and end-date/time of a reservation!
The start- & end-date of the reservation is saved as a timestamp.
The reservations are saved in a mySQL DB.
The user can choose the day in a datepicker:
final DatePicker chooseDay = new DatePicker();
..
Date startDate = reservation.getStartDate();
..
chooseDay.setValue(startDate);
..
2 ListBoxes:
final ListBox startTime = new ListBox();
final ListBox endTime = new ListBox();
..
startTime.addItem("08:00");
startTime.addItem("08:30");
startTime.addItem("09:00"); (til 18:00)
...
endTime.addItem("08:00");
endTime.addItem("08:30");
endTime.addItem("09:00"); (til 18:00)
I now have the problem, that i don't know how to change between the formats. Reservations are saved as a timestamp, but how can i change just day and hour/minute?
I am a beginner and it would be really nice if you can help me. Thank you :)

Use can use JsDate on the client side:
JsDate jsDate = JsDate.create(startDate.getTime());
int hour = jsDate.getHours();
int mins = jsDate.getMinutes();

Related

Using Primeng Datepicker how do I only enable the last day of months?

So my question is pretty simple. I'd like to have specific dates that are enabled on a datepicker, like only the last day of any month, for example 30/06/2019, 31/07/2019
Primng Datepicker
<p-calendar formControlName="date"></p-calendar>
It is a simple hack for your requirement.
In your component.html use min and max date and (onMonthChange) method to update min and max value of date when user changes the month. Trick is just make min and max date equal to last day of the month.
<p-calendar [(ngModel)]="value" tabindex="0" [maxDate]="maxDateValue"
[minDate]="minDateValue" readonlyInput="true"
(onMonthChange)="onMonthChange($event)">
</p-calendar>
And in component.ts file use below code:
public maxDateValue: Date;
public minDateValue: Date;
ngOnInit() {
this.setMinMaxDate();
}
setMinMaxDate() {
var nowdate = new Date();
this.maxDateValue = new Date(nowdate.getFullYear(), nowdate.getMonth() + 1, 0);
this.minDateValue = new Date(nowdate.getFullYear(), nowdate.getMonth() + 1, 0);
}
// method to handle month change.
onMonthChange(e:any) {
this.minDateValue = new Date(e.year, e.month, 0);
this.maxDateValue = new Date(e.year, e.month, 0);
}
You must be thinking why at time of initialization I am using nowdate.getMonth() + 1, but inside onMonthChange only e.month, not adding + 1.
You need to go through this find last and first date of month article how to get the last and first date of a month and print the values of month in console and see the differences. Then you will understand easily.
If you just need one day of each month you should use the month view
<p-calendar [(ngModel)]="dateValue"
view="month" dateFormat="mm/yy"
[yearNavigator]="true"
yearRange="2000:2030"></p-calendar>

PDFbox Document Propperties will not set

In Tutorialspoint is learn about PDFbox.
PDFbox Tutorialpoint
I put an method in my programm to update the metadata from an existing PDF-File.
The Document Properties will not set and i spent many hours to find out why.
When the modification date ".setModificationDate()" will be wrong or coment out, the meatadata of documet properties will not changed.
I dont want to put a static date as the tutorial, i want to insert variables.
//Setting the created date of the document
Calendar date = new GregorianCalendar();
date.set(2015, 11, 5);
//Setting the modified date of the document
date.set(2016, 6, 5);
// Save the metadata to file
pdfDocument.setModificationDate(date);
The data of the ".setModificationDate()" method are want a "Calendar" type.
I do it on different ways and nothing will be work.
Try first
Calendar transfomedDate = new GregorianCalendar();
transfomedDate = convertStringDateToCalendar(StringDate);
Calendar modifiedDate = new GregorianCalendar();
modifiedDate.set(transfomedDate.get(Calendar.YEAR),
transfomedDate.get(Calendar.MONTH),
transfomedDate.get(Calendar.DAY_OF_MONTH),
transfomedDate.get(Calendar.HOUR_OF_DAY),
transfomedDate.get(Calendar.MINUTE),
transfomedDate.get(Calendar.SECOND));
pdfDocument.setModificationDate(modifiedDate);
This Methos will be work correctly on creating Date but not on mofdificationDate?
Then i will trying to put the parameters of the modification in "int" variables and use it on this way.
Calendar transfomedDate = new GregorianCalendar();
transfomedDate = convertStringDateToCalendar(StringDate);
int year = transfomedDate.get(Calendar.YEAR);
int month = transfomedDate.get(Calendar.MONTH);
int day = transfomedDate.get(Calendar.DAY_OF_MONTH)
Calendar modifiedDate = new GregorianCalendar();
// modifiedDate.set(2017, 10, 11);
modifiedDate.set(year, month, day);
pdfDocument.setModificationDate(modifiedDate);
It will not work to.
I dont knwo why PDFbox will not aipdate the metadate when the modficationDate will be commet out or be wrong. I can be ignore the it are wrong?
I dont know what i can do now?
Thanks
Mike

how to increment 1 value in email address for uniqueness in selenium webdriver

I am writing test script for signup page and i need to put email address on each time. Can someone help me how to increment by value 1 in the email address as i execute the script for example, test#test.com and next time value should be test1#test.com. I an try with time stamp but not successfully work.
public class GetCurrentTimeStamp
{
public static void main( String[] args )
{
java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));
}
}
If you are trying to provide always unique email id, then you can use date with seconds as it keep changing also you can use
System.currentTimeMillis()
which gives number always unique. so you can append/concatenate it to email, i hope you know it.
You can use below code to get date
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date)); //2016/04/19 16:05:48
depends of simple date format provide 'yyyy/MM/dd HH:mm:ss' output will be displayed.
Thank You,
Murali
Use java.util.Date class instead of Timestamp and format it like so.
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
String email= "test"+ timestamp + "#test.com";
Use below code:-
int num = 1; // Put this stament outside the for loop or put it as global variable.
Now use below code :-
num++;
String email= "test"+ num + "#test.com";
Hope it will help you :)

How do I convert a Date to an int?

I have this
DateFormat dateFormat = new SimpleDateFormat("MM");
Date date = new Date();
I know the value as 10 but have got no idea how to print it out. How do I convert it to an int? If there even is a way?
date.getMonth()
it is deprecated - you should be using Calendar, but if you don't want to change, that'll do it. It is 0 indexed, so remember to change the resulting value appropriately.
Javadoc

How to modify the date?

I cannot get the add function in Blackberry Java.
// Date
private static DateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
private static Calendar cal = Calendar.getInstance();
public static final String date = dateFormat.format(cal.getTime())
.toString();
The cal variable don't have add function because I want to reduce 1 day from current date.
The source stated that used cal.add(Calendar.DATE, -1);.
The following solution works when using Java SE. I haven't verified using BlackBerry Java ME yet. But, given that I am only using functions that exist in both the SE version of Calendar and the BlackBerry version of Calendar, hence I have a good feeling about the accuracy of this solution. Append these lines to your code:
long curTime = cal.getTimeInMillis();
curTime -= 1000*60*60*24;
cal.setTimeInMillis(curTime);
System.out.println(dateFormat.format(cal.getTime()).toString());
Try this:
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(cal.getTime() - DateTimeUtilities.ONEDAY);
Updated, based on ecb0628's answer and paulkayuk's comment.
Check Calendar, getTimeInMilis(), setTimeInMillis(long millis), and DateTimeUtilities.ONEDAY.