I'm trying to display a clock on my infowindow. The clock runs fine when I it log in the webconsole, but whenever I try to display it on my infowindow, it won't work and it will display "undefined".
I tried adding the GetClock() function which returns the time like this:
var MiamiContent =
'<h3> Miami </h3><br ><h5>'+ setInterval(GetClock, 1000) +' </h5>'
var MiamiInfoCard = new google.maps.InfoWindow
({
content: MiamiContent
});
This is the function that returns the time. It works fine.
tday = new Array("Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat");
tmonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
function GetClock() {
var d = new Date();
var nday = d.getDay(), nmonth = d.getMonth(), ndate = d.getDate(), nyear = d.getYear(), nhour = d.getHours(), nmin = d.getMinutes(), nsec = d.getSeconds(), ap;
if (nhour == 0) { ap = " AM"; nhour = 12; }
else if (nhour < 12) { ap = " AM"; }
else if (nhour == 12) { ap = " PM"; }
else if (nhour > 12) { ap = " PM"; nhour -= 12; }
if (nyear < 1000) nyear += 1900;
if (nmin <= 9) nmin = "0" + nmin;
if (nsec <= 9) nsec = "0" + nsec;
console.log(tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "")
}
window.onload = function () {
GetClock();
setInterval(GetClock, 1000);
}
I'm assuming something is wrong with the way I call the function within the MiamiContent variable since the function does work in my console. Or it's because I log it in my function and the infowindow doesn't know how to "log" things. Help is very much appreciated
If you want the GetClock function to display in the DOM of the InfoWindow, you need to write the code to do that. For example:
var MiamiContent =
'<h3> Miami </h3><br ><h5><span id="clock"></span></h5>'
var MiamiInfoCard = new google.maps.InfoWindow({
content: MiamiContent
});
Then in GetClock:
tday = new Array("Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat");
tmonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
function GetClock() {
var d = new Date();
var nday = d.getDay(),
nmonth = d.getMonth(),
ndate = d.getDate(),
nyear = d.getYear(),
nhour = d.getHours(),
nmin = d.getMinutes(),
nsec = d.getSeconds(),
ap;
if (nhour == 0) {
ap = " AM";
nhour = 12;
} else if (nhour < 12) {
ap = " AM";
} else if (nhour == 12) {
ap = " PM";
} else if (nhour > 12) {
ap = " PM";
nhour -= 12;
}
if (nyear < 1000) nyear += 1900;
if (nmin <= 9) nmin = "0" + nmin;
if (nsec <= 9) nsec = "0" + nsec;
console.log(tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "")
var clockSpan = document.getElementById('clock');
if (!!clockSpan) {
clockSpan.textContent = tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "";
}
}
and you can start the interval timer for the GetClock function in the initMap function.
proof of concept fiddle
code snippet:
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.
function initMap() {
var uluru = {
lat: -25.363,
lng: 131.044
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var MiamiContent =
'<h3> Miami </h3><br ><h5><span id="clock"></span></h5>'
var MiamiInfoCard = new google.maps.InfoWindow({
content: MiamiContent
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
MiamiInfoCard.open(map, marker);
});
setInterval(GetClock, 1000);
}
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
<script>
tday = new Array("Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat");
tmonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
function GetClock() {
var d = new Date();
var nday = d.getDay(),
nmonth = d.getMonth(),
ndate = d.getDate(),
nyear = d.getYear(),
nhour = d.getHours(),
nmin = d.getMinutes(),
nsec = d.getSeconds(),
ap;
if (nhour == 0) {
ap = " AM";
nhour = 12;
} else if (nhour < 12) {
ap = " AM";
} else if (nhour == 12) {
ap = " PM";
} else if (nhour > 12) {
ap = " PM";
nhour -= 12;
}
if (nyear < 1000) nyear += 1900;
if (nmin <= 9) nmin = "0" + nmin;
if (nsec <= 9) nsec = "0" + nsec;
console.log(tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "")
var clockSpan = document.getElementById('clock');
if (!!clockSpan) {
clockSpan.textContent = tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "";
}
}
</script>
Unexpected behavior I first select the timezone in drop-down when I press another timezone in select, the previous selected timezone are save.
function run(){
var timeZone = document.getElementById("selectTimezone");
var i = timeZone.selectedIndex;
var removeParenthesis = timeZone.options[i].text.replace(/[()]/g, '')
var splitString = removeParenthesis.split(' ')
var d = new Date('Nov 1, 2017 ' + ' ' + splitString[0])
var $clock = $('#clock'),
eventTime = moment(d.getTime()).unix(),
currentTime = moment(new Date().getTime()).unix(),
diffTime = eventTime - currentTime,
duration = moment.duration(diffTime * 1000, 'milliseconds'),
interval = 1000;
// if time to countdown
if(diffTime > 0) {
// Show clock
// $clock.show();
setInterval(function(){
duration = moment.duration(duration.asMilliseconds() - interval, 'milliseconds');
var d = moment.duration(duration).days(),
h = moment.duration(duration).hours(),
m = moment.duration(duration).minutes(),
s = moment.duration(duration).seconds();
d = $.trim(d).length === 1 ? '0' + d : d;
h = $.trim(h).length === 1 ? '0' + h : h;
m = $.trim(m).length === 1 ? '0' + m : m;
s = $.trim(s).length === 1 ? '0' + s : s;
// show how many hours, minutes and seconds are left
$('.days').text(d + 'days');
$('.hours').text(h + 'hours');
$('.minutes').text(m + 'minutes');
$('.seconds').text(s + 'seconds');
}, interval);
}
}
https://codepen.io/edward1995/pen/oGpMOq
Clear the interval before starting a new one
var myInterval;// Used to save previous interval if one has been started
function run(){
var timeZone = document.getElementById("selectTimezone");
var i = timeZone.selectedIndex;
var removeParenthesis = timeZone.options[i].text.replace(/[()]/g, '')
var splitString = removeParenthesis.split(' ')
var d = new Date('Nov 1, 2017 ' + ' ' + splitString[0])
var $clock = $('#clock'),
eventTime = moment(d.getTime()).unix(),
currentTime = moment(new Date().getTime()).unix(),
diffTime = eventTime - currentTime,
duration = moment.duration(diffTime * 1000, 'milliseconds'),
interval = 1000;
// if time to countdown
if(diffTime > 0) {
// Show clock
// $clock.show();
clearInterval(myInterval);
myInterval = setInterval(function(){
duration = moment.duration(duration.asMilliseconds() - interval, 'milliseconds');
var d = moment.duration(duration).days(),
h = moment.duration(duration).hours(),
m = moment.duration(duration).minutes(),
s = moment.duration(duration).seconds();
d = $.trim(d).length === 1 ? '0' + d : d;
h = $.trim(h).length === 1 ? '0' + h : h;
m = $.trim(m).length === 1 ? '0' + m : m;
s = $.trim(s).length === 1 ? '0' + s : s;
// show how many hours, minutes and seconds are left
$('.days').text(d + 'days');
$('.hours').text(h + 'hours');
$('.minutes').text(m + 'minutes');
$('.seconds').text(s + 'seconds');
}, interval);
}
}
var LR_No_Of_Days = "";
$("#DateRange").jqxDateTimeInput({ width: 250, height: 25, selectionMode: 'range' }); $("#DateRange").on('change', function (event) {
var selection = $("#DateRange").jqxDateTimeInput('getRange');
if (selection.from != null) {
$("#selection").html("<div>From: " + selection.from.toLocaleDateString() + " <br/>To: " + selection.to.toLocaleDateString() + "</div>");
}
var LR_Request_Date_From = selection.from.toLocaleDateString();
var LR_Request_Date_To = selection.to.toLocaleDateString();
$('#LR_Request_Date_From').val(LR_Request_Date_From);
$('#LR_Request_Date_To').val(LR_Request_Date_To);
NoOfdays();
function NoOfdays() {
var LR_No_Of_Days = Math.floor((Date.parse(LR_Request_Date_To) - Date.parse(LR_Request_Date_From)) / 86400000); if (LR_No_Of_Days == '0') {LR_No_Of_Days = 1;} else { LR_No_Of_Days-1; }; alert(LR_Request_Date_From + " &&& " + LR_Request_Date_To + " No of days:" + LR_No_Of_Days);
$("#LR_No_Of_Days").val(LR_No_Of_Days);}});
I'm unable to convert the string variable(LR_Request_Date_From and LR_Request_Date_To) to date format. I receive error converting string to date.
You have to use MM instead of mm and CultureInfo.InvariantCulture as second parameter
string dt = DateTime.Parse(txtVADate.Text.Trim()).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
Test Code :
> String x = "30000000000.222";
> String y = "20000000000.444";
> double x1 = Double.parseDouble(x);
> double y1 = Double.parseDouble(y);
>
> ContentValues vValue51 = new ContentValues();
> vValue51.put(DatabaseStructure.fTmpAttr_X3 , x1 );
> vDatabase.insertData(DatabaseStructure.cTblTemporary3, vValue51);
> ContentValues vValue61 = new ContentValues();
> vValue61.put(DatabaseStructure.fTmpAttr_X3 , y1 );
> vDatabase.insertData(DatabaseStructure.cTblTemporary3, vValue61);
> vDatabase.closeDatabase();
>
>
>
> List<Map<String, String>> vListData2 = new
> ArrayList<Map<String,String>>(); String vQuerY32;
>
>
> vQuerY32 = "Select SUM(" + DatabaseStructure.fTmpAttr_X3 + " ) 'jik' " +
> "From " + DatabaseStructure.cTblTemporary3;
>
> vDatabase = new DatabaseHandler(getApplicationContext());
> vListData2 = vDatabase.getListData(vQuerY32);
> vDatabase.closeDatabase();
I tried many data type for column
> vQuery = "create table " + cTblTemporary3 +
> "("+
> fTmpAttr_ID3 + " integer primary key, " +
> fTmpAttr_V3 + " DECIMAL(10,5), " +
> fTmpAttr_W3 + " FLOAT , " +
> fTmpAttr_X3 + " REAL, " +
> fTmpAttr_Y3 + " DOUBLE PRECISION, " +
> fTmpAttr_Z3 + " double " +
> ")"; vSQL.execSQL(vQuery);
======================getListDataFunction===========================================
public List<Map<String, String>> getListData(String vQuery)
{
List<Map<String, String>> vListData = new ArrayList<Map<String,String>>();
Cursor vCursor = getCursorData(vQuery);
int vLength = vCursor.getColumnCount();
String[] vFields = new String[vLength];
if (vCursor.getCount() > 0){
for (int i = 0; i < vLength; i++)
vFields[i] = vCursor.getColumnName(i);
vCursor.moveToFirst();
while (!vCursor.isAfterLast()) {
Map<String, String> vMapData = new HashMap<String, String>();
for (int i = 0; i < vLength; i++)
vMapData.put(vFields[i], vCursor.getString(i));
vListData.add(vMapData);
vCursor.moveToNext();
}
}
vCursor.close();
return vListData;
}
i Log the result
Log.d("TEST", vListData2.get(0).get("jik"));
, the result is not 50000000000.666 but 5e+10, How i can get 50000000000.666 for the result? Please help this newbie :(
the date in excel is of the date time format and the selected date is also date time format but wots the problem
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT [ProjectId],[ProjectName],[ManagerID],[ManagerName],[AllocationStartDate],[AllocationEndDate],[horizontalshortname] FROM [" + getExcelSheetName + #"] where [horizontalshortname]="+ "'" + TextBox_Horizontal.Text + "'"
+ " AND [Isonsite]=" + "'" + DropDownList_Location.SelectedItem.Text + "'"
+ " AND [AllocationStartDate]>="+Calendar1.SelectedDate
+ " AND [AllocationEndDate]<="+Calendar2.SelectedDate
, conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
//if (ds.Tables[0] != null )
if (ds1.Tables[0].Rows.Count > 0)
{
GridView_Utilization_Search.Visible = true;
GridView_Utilization_Search.DataSource = ds1.Tables[0];
GridView_Utilization_Search.DataBind();
}
else
{
GridView_Utilization_Search.Visible = false;
}