I am trying to convert date format in the Sahi Pro using the following code but no luck:
I want to convert "Thursday 02 Mar 2017" into "03/02/2017"
_setValue(_textbox("j_username"), "*******");
_setValue(_password("j_password"), "*******");
_click(_span("Login"));
_click(_span("Home"));
_wait(2000);
var $date = _getText(_div("/date-display .* bwc-selected/"));
_wait(2000);
_log($date);
_wait(2000);
var $date = _getText(_div("/date-display .* bwc-selected/"));
var $old_date_format = new java.text.SimpleDateFormat(_getText(_div("/date-display .* bwc-selected/"))).parse($date);
var $converted_date_format = new java.text.SimpleDateFormat("MM/dd/yyyy").format($old_date_format);
_log($converted_date_format);
After running above code I am getting following error for formatting fate:
Wrapped java.lang.IllegalArgumentException: Illegal pattern character 'T' (C:\SahiPro\userdata\scripts\Trial.sah#11)
I did some research on Java script and came up with following solution:
Following code converted "Thursday 02 Mar 2017" into "03/02/2017"
var $date = _getText(_div("/date-display .* bwc-selected/"));
_wait(2000);
_log($date);
_wait(2000);
var str = ($date)
var d = new Date(str)
var $systemDate = (d.getUTCMonth()+1) +"/"+ d.getUTCDate() + "/" + d.getUTCFullYear();
_log($systemDate);