Javascript GMT string convert to Local Time - datepicker

$(function() {
$('#datepicker').datepick({
multiSelect: 999,
monthsToShow: 3,
minDate: new Date(),
maxDate: '+1y',
showTrigger: '#calImg',
dateFormat: 'yy-mm-dd',
onSelect: function(value) {
alert(value);
}
});
});
this code block returns a string like that "Wed Jan 11 2012 12:00:00 GMT+0100".
How can I convert that string like that "2012-01-11 12:00:00"?

You can use this to covert to local time and get rid of GMT
function getLocalTimeFromGMT(sTime){
var dte = new Date(sTime);
dte.setTime(dte.getTime() - dte.getTimezoneOffset()*60*1000);
document.write(dte.toLocaleString()); }
cf http://teck.in/indian-standard-time-and-gmt-from.html#ixzz1hNGiQAhg

Related

How do I set timeout for LocalNotification

How do I set timeout like example I want the notification to be
Trigger start from (27 Nov 2020, 12pm)
Subsequently every one hour until 28 Nov 2020, 12pm.
Without reopening the app, heres my codes.
var mySchedule: LocalNotificationSchedule = {
on:"27 Nov 2020, 12pm",
repeats: true,
every: 'hour',
count:1,
#until : "28 Nov 2020, 12pm"
};
var notification={};
notification["title"]="Local Notification Test";
notification["body"]="Example body";
notification["id"]="2";
notification["schedule"]=mySchedule;
notification["sound"]="default";
this.localNoti.push(notification);
const notifs = await LocalNotifications.schedule({
notifications: this.localNoti
});

Display the name of the month in the date

I display a date range in my code, which appears as this: 06-08-2017 - 12-08-2017.
But what I would like to see is this: 06 August - 12 August
I wondered how to do it.
Here is the code I use to display dates:
<script>
$(document).ready(function() {
var startDate;
var endDate;
// configure the bootstrap datepicker
var selectCurrentWeek = function() {
window.setTimeout(function () {
$('#js-datepicker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
}, 1);
}
$('#js-datepicker').datepicker({
//config default
altField: "#datepicker",
closeText: 'Fermer',
prevText: 'Précédent',
nextText: 'Suivant',
currentText: 'Aujourd\'hui',
monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
monthNamesShort: ['Janv.', 'Févr.', 'Mars', 'Avril', 'Mai', 'Juin', 'Juil.', 'Août', 'Sept.', 'Oct.', 'Nov.', 'Déc.'],
dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
dayNamesShort: ['Dim.', 'Lun.', 'Mar.', 'Mer.', 'Jeu.', 'Ven.', 'Sam.'],
dayNamesMin: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
weekHeader: 'Sem.',
dateFormat: 'dd-mm-yy',
firstDay: 1,
showOtherMonths: true,
selectOtherMonths: true,
onSelect: function(date,obj){
var daty = $(this).datepicker('getDate');
console.log(daty);
startDate = new Date(daty.getFullYear(), daty.getMonth(), daty.getDate() - daty.getDay());
endDate = new Date(daty.getFullYear(), daty.getMonth(), daty.getDate() - daty.getDay() + 6);
var dateFormat = obj.settings.dateFormat || $.datepicker._defaults.dateFormat;
$('#startDate').text($.datepicker.formatDate( dateFormat, startDate, obj.settings ));
$('#endDate').text($.datepicker.formatDate( dateFormat, endDate, obj.settings ));
selectCurrentWeek();
date = $.datepicker.formatDate('dd-mm-yy', daty);
console.log(date);
$('#date_input').val(date);
}
});
});
</script>
Thank you
Try this :
dateFormat: 'dd-MMMM',
A good library for date format is
http://momentjs.com
From the documentation
moment().format('MMMM Do YYYY, h:mm:ss a'); // August 13th 2017, 8:26:44

Count days between two dates excluding weekends

How can I find the difference between two dates in DB2 (excluding weekends)?
Are there any functions that will do this in DB2? Or do I need to write a query myself?
There is AFAIK no such function. It is however easy to write a query that calculates this:
with cal(d) as (
values date('2015-01-01') -- start_date
union all
select d + 1 day from cal
where d < '2015-01-15' -- end_date
) select count(case when dayofweek(d) between 2 and 6 then 1 end)
from cal;
If you do a lot of these kind of calculations you might want to create a calendar table, you can add attributes like national holiday etc to this table.
you can use this function:
DAYOFWEEK(CURRENT_DATE)
The following calculation will return the number of working days between two dates:
[Week(End Date) - Week(Start Date)] * 5 + [DayofWeek(Start Date) - DayofWeek(End Date)]
This will only work if the functions for Week and Day or equivalent are native to the database driver. Client Access and Sybase native connection both support these functions.
The Week function will give the integer value of the week of the year selected. The DayofWeek will give an Integer value from 1-7 for the day selected.
IBM Support Working Days Between Two Dates
This is the best way to implement difference between two dates excluding weekend means Saturday and Sunday and also excluding national holiday....
/******
* First, we'll extend the date object with some functionality.
* We'll add an .each() function, as well as an .adjust() function.
* .each() will give us the ability to loop between two dates, whether
* by 'day', 'week' or 'month'.
* .adjust() will allow us to move a given day by a given unit. This is used
* like so: currentDate.adjust('days', 1) to increment by one day.
******/
Date.prototype.each = function(endDate, part, step, fn, bind){
var fromDate = new Date(this.getTime()),
toDate = new Date(endDate.getTime()),
pm = fromDate <= toDate? 1:-1,
i = 0;
while( (pm === 1 && fromDate <= toDate) || (pm === -1 && fromDate >= toDate) ){
if(fn.call(bind, fromDate, i, this) === false) break;
i += step;
fromDate.adjust(part, step*pm);
}
return this;
};
Date.prototype.adjust = function(part, amount){
part = part.toLowerCase();
var map = {
years: 'FullYear', months: 'Month', weeks: 'Hours', days: 'Hours', hours: 'Hours',
minutes: 'Minutes', seconds: 'Seconds', milliseconds: 'Milliseconds',
utcyears: 'UTCFullYear', utcmonths: 'UTCMonth', weeks: 'UTCHours', utcdays: 'UTCHours',
utchours: 'UTCHours', utcminutes: 'UTCMinutes', utcseconds: 'UTCSeconds', utcmilliseconds: 'UTCMilliseconds'
},
mapPart = map[part];
if(part == 'weeks' || part == 'utcweeks')
amount *= 168;
if(part == 'days' || part == 'utcdays')
amount *= 24;
this['set'+ mapPart]( this['get'+ mapPart]() + amount );
return this;
}
/*******
* An array of national holidays. This is used to test for the exclusion of given
* days. While this list is national days, you could tailor it to regional, state
* or given religious observances. Whatever.
******/
natDays = [
{
month: 1,
date: 26,
type: "national - us",
name: "New Year's Day"
},
{
month: 1,
date: 21,
type: "national - us",
name: "Martin Luther King Day"
},
{
month: 2,
date: 18,
type: "national - us",
name: "President's Day (Washington's Birthday"
},
{
month: 5,
date: 27,
type: "national - us",
name: "Memorial Day"
},
{
month: 7,
date: 4,
type: "national - us",
name: "Independence Day"
},
{
month: 9,
date: 2,
type: "national - us",
name: "Labor Day"
},
{
month: 10,
date: 14,
type: "national - us",
name: "Columbus Day"
},
{
month: 11,
date: 11,
type: "national - us",
name: "Veteran's Day"
},
{
month: 11,
date: 29,
type: "national - us",
name: "Thanksgiving Day"
},
{
month: 12,
date: 25,
type: "national - us",
name: "Christmas Day"
}
];
/******
* This uses the national holidays array we just set, and checks a given day to see
* if it's in the list. If so, it returns true and the name of the holiday, if not
* it returns false.
*****/
function nationalDay(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == (natDays[i].month-1)
&& date.getDate() == natDays[i].date) {
return [true, natDays[i].name];
}
}
return [false, null];
}
/******
* This function takes two dates, as start and end date, and iterates through the
* dates between them. For each date, it checks if the current date is a week day.
* If it is, it then checks if it isn't a holiday. In this case, it increments
* the business day counter.
******/
function calcBusinessDays(startDate, endDate) {
// input given as Date objects
var iDateDiff=0, holidays = [];
startDate.each(endDate, 'days', 1, function(currentDate, currentStep, thisDate){
if(currentDate.getDay() != 0 && currentDate.getDay() != 6 ) {
var isAHoliday = nationalDay(currentDate);
if(!isAHoliday[0]){
iDateDiff += 1;
} else {
holidays.push(isAHoliday[1]);
}
}
});
return {count: iDateDiff, holidays: holidays};
};
$(function(){
var results, exclusions;
$( "#startDate" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#endDate" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#endDate" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#startDate" ).datepicker( "option", "maxDate", selectedDate );
}
});
$("#calculateMe").on("click", function(){
var startDate = new Date($("#startDate").val()),
endDate = new Date($("#endDate").val() );
// Calculate the number of business days. This returns an object, with
// two members: count and holidays
results = calcBusinessDays(startDate, endDate);
exclusions = "Excluded weekends";
if (results.holidays.length > 0) {
// We have holidays, tell the user about them...
exclusions += " and the following holidays: ";
for(var i=0; i<results.holidays.length; i += 1){
exclusions += results.holidays[i]+", ";
}
} else {
// No holidays.
exclusions += ".";
}
$("#result").text(results.count + " business days." ).append("<p>("+exclusions+")</p>");
});
});
<div id="content">
<input type="text" class="myDateClass" id="startDate"/>
<input type="text" class="myDateClass" id="endDate"/>
<button id="calculateMe">How many business days?</button>
<div id="result"></div>
</div>
Fiddle

Datepicker MinDate maxDate, maxDate = datestart + 3 months

Using the basic two input field datepicker format.
http://jqueryui.com/datepicker/#date-range
Input1:
$(function() {
$("#DATE_START").datepicker({ showOtherMonths: true, minDate: +1, dateFormat:"yy-mm-dd", });
});
Input2:
$(function() {
$("#DATE_END").datepicker({ showOtherMonths: true, changeMonth: true, changeYear: true, minDate: +2, dateFormat:"yy-mm-dd", });
});
Issue:
I want the DATE_END to be DATE_START input value, plus 3 months.
EX: maxDate = DATE_START + '3m'
Not needed current date plus 3 months
Thanks
You have just to set the Date like this:
$(function() { $("#DATE_START").datepicker({ showOtherMonths: true, minDate: "+3m", dateFormat:"yy-mm-dd", }); })
$( "#DATE_END" ).datepicker.datepicker({ showOtherMonths: true, minDate: "+3m", dateFormat:"yy-mm-dd", }); })
Have a look on the documentation. Its pretty good.
http://api.jqueryui.com/datepicker/#option-minDate
You can also use this to set the date:
$( ".selector" ).datepicker( "setDate", "10/12/2012" );

why don't I get anything returned from mongo with this jugglingdb query

I am using compoundjs with jugglingdb to get some data from Mongo.
in my code I have the following
Hotspot.all({ where : { fromid : imageMappingWidget.id } },
function (err, hotspots) {
console.log(hotspots);
for (i in hotspots) {
var hotspot = hotspots[i];
hotspot.destroy();
console.log("removed" + hotspot);
};
});
the console.log of hotspots outputs an empty array, and I of course never get in to the loop.
My imageMappingWidget object is
{ schema_version: 1,
name: 'Testing 2',
image: null,
width: '3264',
height: '2448',
createDate: Sun Aug 24 2014 14:27:56 GMT+0200 (CEST),
updateDate: Sun Aug 24 2014 14:27:56 GMT+0200 (CEST),
uploadedImage: true,
requiredWidth: null,
id: 53f9da4c1ef48ced2a000001}
However if I do the following query from mongo on the command line
db.Hotspot.find({ fromid: "53f9da4c1ef48ced2a000001"})
I get exactly one record back.
I thought, immediately after asking - why don't I just try to see if tostring on the id will help, and it did.
grrrr.