i'm trying to read a file by date with JS
i tried to replace the varable TimeNow without success.
when fo example i make fixed filename it works fine, but replacing the filename with a variable 'TimeNow' it doesnt work.
var prex = document.querySelector('pre');
var DateNow = new Date();
DateNow.setHours(DateNow.getHours()-1);
var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
loadCSV("counters_test_directory_${TimeNow}.log");
prex.innerHTML += '\n\n';
prex.innerHTML += TimeNow;
<pre>
</pre>
loadCSV(`counters_test_directory_${TimeNow}.log`);
var prex = document.querySelector('pre');
var DateNow = new Date();
DateNow.setHours(DateNow.getHours()-1);
var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
alert(`counters_test_directory_${TimeNow}.log`);
// The source of this function is NOT given.
//loadCSV(`counters_test_directory_${TimeNow}.log`);
prex.innerHTML += '\n\n';
prex.innerHTML += TimeNow;
<pre>
</pre>
Related
I am trying to print the log for following JavaScript. However, script is not printing the log value. I highlighted the variable value the script should identify in the if/else code, however after else it is not reading the $systemDate from outside the if/else statement; as a result it is not logging the value for $dueDate. I am trying following code:
_wait(_div("/date-display .* bwc-selected/"));
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('System Date is:' + $systemDate);
var $dueDate = person.$dueDate;
if ($dueDate != null)
{
var $dueDate = person.$dueDate;
person.$dueDate = $dueDate;
_log('Due Date is:' + $dueDate);
}
else
{
var $days = 90;
var $theDate = new Date($systemDate);
var $pregnancyDueDate = new Date($theDate);
$pregnancyDueDate.setDate($pregnancyDueDate.getDate() + $days);
var due = ($pregnancyDueDate);
var n = new Date(due);
var $dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
_log('Due Date is:' + $dueDate);
person.$dueDate = $dueDate;
}
Do not redeclare your variable !
remove var from
var $dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
it should be:
$dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
You variable was already declared here before your if
var $dueDate = person.$dueDate;
and finally update your if condition to :
if ($dueDate != "")
because your cells can be just empty and not containing null values
Iam working in cordova with cordova-local-notifications plugin. First the clear function was working but now when I clear and restart the application the notification all show up...
This is my clear function:
$('.clearbtn').click(function(){
var arraylength = info.data;
arraylength.splice(0,arraylength.length);
console.log('clear',arraylength);
});
The console log shows me that the array has nothing inside it. And this is the outcome of the console.log(info.data)
and this is the all reminder page:
$(document).on("pagebeforeshow","#all",function(){
var html = '';
for(var count = 0; count < info.data.length; count++){
console.log(info.data);
var time = new Date(info.data[count][3]);
var addHour = time.setHours(time.getHours());
var date = new Date(addHour);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Will display time in 10:30:23 format
var formattedTime = hours + ':' + minutes.substr(-2);
var imgPath = 'img/icons/alert.png';
html = html + "<tr><td class='img-table'><img src=" + imgPath + "></td>" + "<td><span class='time-aside'><strong>" + formattedTime + "</strong></span><h4>" + info.data[count][1] + "</h4><p>" + info.data[count][2] + "</p></td></tr>";
}
$('.clearbtn').click(function(){
var arraylength = info.data;
arraylength.splice(0,arraylength.length);
console.log('clear',arraylength);
});
$("table#notificationTable tbody").empty();
$("table#notificationTable tbody").append(html).closest("table#notificationTable").table("refresh").trigger("create");
});
I really don't get it because it was working before but I don't know why its not anymore!
I had to clear localStorage aswell.. Because I push it to localstorage as string. Here is a rewrite of the function:
$('.clearbtn').click(function(){
var arraylength = info.data;
arraylength = 0;
localStorage.clear();
});
I want to download my HTML table as Excel. For that I used the given code
$('#export').click(function (e) {
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
var a = document.createElement('a');
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('reportDiv');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
a.download = 'UserMatrix' + postfix + '.xls';
a.click();
e.preventDefault();
});
It's working in Chrome and Firefox but not working in Internet Explorer 9.
You'd need to use an alternate solution for IE9 as it doesn't support the HTML download attribute for the anchor tag.
Here's a popular Javascript option:
https://github.com/dcneiner/Downloadify
It uses Flash, though, which IE 9 would support.
I'm fairly new to javascript and I need to rename or add to an extension of a css and .png file. The script is embedded within an ETL process. I have a variable "prd" that holds the value of the file name that the style.css and picture.png file are derived from and I also need to add a date or time stamp to the end of the extension. Basically I'm wanting to concatenate prd+style_02_06_14.png
Desired results:
Prd = sales_report
File = style.css.
Result = "sales_report_style_02_06_14.png" and "sales_report_style_02_06_14.css"
Here is my code
var sourceCssFile = outputfolder + "style.css";
var destinationCssFile = outputfolder + css_pic;
if(isFolder(destinationCssFile) == false) {
createFolder(destinationCssFile);
var testvar = "inside";
}
destinationCssFile = destinationCssFile + "/style.css";
moveFile(sourceCssFile, destinationCssFile, true);
var sourceImageFile = outputfolder + "picture.png";
var destinationImageFile = outputfolder + css_pic + "/picture.png";
moveFile(sourceImageFile, destinationImageFile, true);
var cont = loadFileContent(output);
var replaceCss = css_pic + "tt+style.css";
var replaceImg = css_pic + "tt + picture.png";
cont = cont.replace("style.css", replaceCss);
cont = cont.replace("picture.png", replaceImg);
var filename = outputfolder + new_str;
Try this:
function formatResult(prd, filename, date, extension) {
return prd + '_' + filename + '_' + formatDate(d) + '.' + extension;
}
function formatDate(d) {
var year = d.getFullYear().toString().substr(2,2);
var month = (d.getMonth()+1) + '';
if (month.length == 1) {
month = "0" + month;
}
var day = d.getDate() + '';
if (day.length == 1) {
day = "0" + day;
}
return month + '_' + day + '_' + year;
}
Demo
http://jsfiddle.net/WHpuU/5/
Nota
alert( 'style.css'.replace(/\.css$/i, '') ); // shows 'style'
I am calculating on date part through java script , but it is giving NAN-NAN-NAN in Firefox and chrome while working fine in IE . My code is below which is i am using.
var datedisp = $("#txtDateinputBox_startdate").val();
datedisp = datedisp.split("/");
var month = datedisp[0];
var year = datedisp[2];
var dtepart = eval(datedisp[1]);
var moddate = dtepart + SetID - 1;
var finaldate = month + '-' + moddate + '-' + year;
var disp_fdate = new Date(finaldate);
//alert(finaldate);
var disp_date = disp_fdate.getDate();
//var disp_date = disp_fdate.getUTCFullDate();
var disp_month = disp_fdate.getMonth() + 1;
var disp_year = disp_fdate.getYear();
var uidate = eval(disp_month) + '-' +eval( disp_date) + '-' + eval(disp_year);
and then this uidate is using in div creation.
Please Help
Thanks In Advance
This?
var date, i, string;
function date_to_string( date ) {
return ( date.getMonth() + 1 ) + '-' + date.getDate() + '-' + date.getFullYear();
}
date = new Date( '01/27/2012' );
for ( i = 0; i < 14; i += 1 ) {
date.setDate( date.getDate() + 1 );
string = date_to_string( date );
// use string
}
Live demo: http://jsfiddle.net/ekaDg/