Extract UTC time with jsoup by id - java

I am trying to extract the Current Unix epoch time in milliseconds from this website but I failed. Here is my code
Document document = Jsoup.connect("https://www.freeformatter.com/epoch-timestamp-to-date-converter.html").get();
String content = document.getElementById("epochMs").text();
For some reason, the content is empty. Maybe I need to click on the href link first to stop the running timer? Any idea how to get the timestamp?

Related

Cannot select a date range from jquery datepicker date range selector in Selenium JAVA

I'm struggling with selecting a date range from jquery datepicker date range selector using selenium web driver.
Following image shows the date picker.
I need to select a date range from this calendar. I've tried following links.
Link 1
Link 2
Only thing i found relevant is the following code segment.
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#class='demo-frame'][#src='/resources/demos/datepicker/default.html']")));
driver.findElement(By.id("datepicker")).click();
System.out.println("Datepicker Clicked");
But, it doesn't show how to select a date range from the date picker.
Thanks in advance. :-)
From my experience, it makes no sense to interact with such components via findElement calls. Unless you want to make your tests unstable. Such datepickers usually have public API, which could be accessed directly via JavascriptExecutor. Quick sample:
$( ".selector" ).datepicker( "setDate", "10/12/2012" );
could be used the following way:
executeScript("$( '.selector' ).datepicker( 'setDate', '10/12/2012' );");
So I'd recommend you to find out which JS library is used to render your datepicker, check their API, and access it directly the way I've written above.
Give a try to below code and lets see if it works.
I stole the code from select the Date Picker
((JavascriptExecutor)driver).executeScript ("document.getElementById('elementid').removeAttribute('readonly',0);"); // Enables the from date box
WebElement dateBox= driver.findElement(By.id("elementid"));
dateBox.clear();
dateBox.sendKeys("8-Dec-2014"); //Enter date in required format

Selenium web driver Date picker exists in page after the send keys?

I'm using send keys to input the value in date picker.. this is working absolutely fine, but most of the times date picker still displaying in the page after the send keys!! any idea how to remove date picker in page after the send keys???
Thanks in advance!!
If you click on the date picker, the date picker will be close automatically.
But you use send keys to input the value, you should send the key Enter after it.
Try to do it manually.

CQ-Getting date and time as raw strings using xtype="datetime"

I am pretty new to CQ and I am adding a new field to an existing form.
I want to accept a date and time from the component dialog as strings. If I use xtype="datefield" and xtype="timefield" separately, I can get the date and time as strings just the way I need it. But, the UI looks bad and non-intiutive with two separate fields placed one below the other.
dialog.xml:
<startDate
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Date"
fieldDescription="Select a date "
emptyText="Event start date "
name="./startDate"
format="d/m/Y"
xtype="datefield" />
<startTime
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Time"
fieldDescription="Select a time "
emptyText="Event start time "
name="./startTime"
xtype="timefield" />
Java code in controller:
#Property(path = "startDate")
private String startDate;
#Property(path = "startTime")
private String startTime;
If I use xtype="datetime", the UI looks the way I like but the value is converted to UTC into a Date field.
dialog.xml
<startDateTime
jcr:primaryType="cq:Widget"
fieldLabel="Start Date & Time"
name="./startDateTime"
dateFormat="d/m/Y"
xtype="datetime"/>
Java code in controller:
#Property(path = "startDateTime")
private Date startDateTime;
This is of no use to me as I need the date and time as raw strings, the way they were entered. The need for obtaining date & time as strings is driven by the requirement which states 'The author should be able to enter a specific date and time that an event starts and ends at a particular city. So the author enters the date, time and timezone of the event'. I need to display the date&time on the page and also add a calendar link. The valueAsString option looked promising but does not give me date and time as strings. How can I achieve this?
Thanks in Advance
UPDATE:
Using the xtype="compositefield" suggested by #Sharath, I can achieve the desired UI but unfortunately the values are retained when I edit the component. The values are entered accurately and I can display it on the screen but when the component is edited, the fields go back to being empty. There were no changes in the java file.
Updated dialog.xml:
<items jcr:primaryType="cq:WidgetCollection">
<eStart jcr:primaryType="cq:Widget"
xtype="compositefield"
fieldLabel="Start"
fieldDescription="Select event start date & time">
<items jcr:primaryType="cq:WidgetCollection">
<startDate
jcr:primaryType="cq:Widget"
emptyText="Event start date "
name="./startDate"
format="d/m/Y"
xtype="datefield"
width="240"/>
<startTime
jcr:primaryType="cq:Widget"
emptyText="Event start time "
name="./startTime"
xtype="timefield"
width="180"/>
</items>
</eStart>
*
*
</items>
There are two ways to do this :
1) Use a compositefield and place the date and time fields within it. Compositefield displays the widgets within it in a horizontal row. With this method the fields will be displayed like the datetime xtype but still store values independently as strings.
2) Use datetime xtype and read the value as String instead of Date and split the value by "T". (I'd go with 1)
I think i was wrong about the composite field, it displays and stores the value but does not read back the values next time (inspite of the get request to the node returning those values )
Here's an alternative
{
xtype:"panel",
border:false,
layout:"hbox",
jcr: primaryType:"cq:Widget",
items:{
jcr: primaryType:"cq:WidgetCollection",
label:{
flex:"30",
xtype:"label",
jcr: primaryType:"cq:Widget",
text:"Date Time"
},
datefield:{
flex:"40",
xtype:"datefield",
name:"./date",
jcr: primaryType:"cq:Widget"
},
timefield:{
flex:"30",
xtype:"timefield",
name:"./time",
jcr: primaryType:"cq:Widget"
}
}
}
I think datetime is the easier option. With the Date object you can then use http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html to get the date in the required format.
You can use the same formatting in the dialog as well as the output.
Another advantage is that you could filter and sort nodes of this type by Date, as opposed to save the values as Strings.

How to enforce format for String date in jsf 1?

i am sending hijri date to jsp page as String like:
1435/06/01
the format is YYYY/MM/DD
and in the ui:table when i make inspect element i can see the date as required 1435/06/01
but in the page is displayed as 1435/06/01 because the client windows date and time format is Arabic
but when the client changes the windows date and time format to english the date is displayed correctly.
is there's a way to enforce the display of my date and numbers to be exactly like the value i send from backend and ignore the client system date and time format ?

Verify Apple iOS iTunes receipt; 0-based or 1-based hour

I am writing a Java servlet that will verify whether Apple receipt-date from an iOS in-app purchase is valid or not, and to get a receipt object to return to the iOS client. The specification of this verification are in this page from the official iOS documentation.
In the verified and converted receipt object (a JSON returned to the servlet by Apple via HTTP Post), an example a date string is this: 2012-01-13 10:14:24 America/Los_Angeles. I want to write a Jackson JSON deserializer that will convert the String into a Joda DateTime object.
Problem: I am not sure whether the hour field of the timestamp is 0-based or 1-based. If it was 0-based, then I would create a DateTimeFormatter using HH to specify the hour field. Conversely, if it was 1-based, then I would use kk. Please see the Javadoc for DateTimeFormat for more info about how to write the timestamp configuration String.
Does anyone know whether the timestamp from Apple is 0-based or 1-based? As I do not yet have an active iTunes app (my test timestamp was from an example receipt), I am unable to write a test for this. Thank you!
From: Verifying Store Receipts you can get that purchase_date is a transactionDate, and transactionDate NSDate. From Date Formatters you can see that the used hour format is HH:mm.

Categories