I am trying to set a specific time to two variables but can't seem to correctly format the syntax. I want to be able to set Shift 1 and Shift 2 off of certain times indicated below.
I want to only be able to use these times in an IF statement so that a radio button can be checked by default. Day Shift button and a Night Shift button. If the current time is in between shift 1, then day shift button is checked.
Date.prototype.currentTime = function(){
return ((this.getHours()>12)?(this.getHours()-12):this.getHours()) +":"+ this.getMinutes()+((this.getHours()>12)?('PM'):'AM'); };
var d1= new Date();
var d2 = new Date();
d1.setHours(7);
d1.setMinutes(10);
d2.setHours(19);
d2.setMinutes(10);
alert(d1.currentTime());
alert(d2.currentTime());
Thanks Any help is appreciated.
You do not need to compare Date objects for your use,
just compare the hours as integers to the integer from now.getHours():
var now= new Date().getHours();
if(now>6 && now<19){
//check day shift button;
}
// else check niteshift button
You may try this:
http://jsfiddle.net/apq59j9u/
Date.prototype.currentTime = function(){
return ((this.getHours()>12)?(this.getHours()-12):this.getHours()) +":"+ this.getMinutes()+((this.getHours()>12)?('PM'):'AM'); };
var d1= new Date();
var d2 = new Date();
d1.setHours(7);
d1.setMinutes(10);
d2.setHours(19);
d2.setMinutes(10);
alert(d1.currentTime());
alert(d2.currentTime());
Getting the Data
There are a number of different ways to do this. First here is a way to get the data from the date object:
var d = new Date();
var n = d.toTimeString();
Unfortunately, this will output something like "12:30:30 GMT-0500 (Eastern Standard Time)"
You can also try the getHours() and getMinutes functions to get the hours and minutes in your current timezone.
var d = new Date();
var hours = d.getHours();
var minutes = d.getMinutes();
Setting the Data
This is pretty easy to do, just as getting the data from a date object. Use the following code to set the time to what you would like. Replace the numbers where you see 11 to conform to your needs.
NOTE: This time is in military style hours! 1 = 1am, 13 = 1pm, ect.
var d = new Date();
d.setHours(11);
d.setMinutes(11);
d.setSeconds(11);
Result: 11:11:11
Related
I am fairly new to Google Apps Script and I am trying to create a function where it converts the selected cells to a dd/mm/yyyy format. The format the dates are in originally looks like this 2022-01-03 15:00:00 +1100.
I've managed to change the format of the date so it shows up correctly on the logger but when I select the cells and run the function via a menu it just shows up as the last value.
Any help with this would be appreciated. Thank you!!!
function dateconverter(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var selectedContent = ss.getActiveRange().getValues();
var getRange = ss.getActiveRange().getA1Notation()
for(var x =0;x<selectedContent.length;x++){
var fixed = selectedContent[x].join().split(' ');
var dateStr = fixed[0].split('-').join()
var year = +dateStr.substring(0, 4)
var month = +dateStr.substring(5, 7)
var day = +dateStr.substring(8, 10)
var pubdate = [`${day}/${month}/${year}`]
Logger.log(pubdate)
}
ss.getRange(getRange).setValue(pubdate)
}
Use :- Utilities.formatDate(new Date(),Session.getTimeZone,"dd/MM/yyyy")
I have a need to get the offset (in hours) for any given time zone in Adobe ColdFusion. The idea is to pass in a time zone (America/Phoenix) and get back it's offset taking into account daylight savings.
Well after looking for what seemed forever, I realized CF doesn't have a way to do it. You need to delve into it's underbelly (JAVA) to get what you need. So, with a little help from a post by Ben Nadel on time zones, I figured it out and decided to pass on what I learned to a fellow dev traveler who may need it one day.
<cfscript>
/*
Author: Steve Holland (Avant Solutions Group)
Website: www.avantsolutionsgroup.com
License: https://opensource.org/licenses/MIT
*/
private struct function calcTZOffset(required string timeZoneID, boolean returnTimezones="false") {
// Init the timezome java class
var tz = createObject( "java", "java.util.TimeZone" );
// Get the timezone info
var tzInfo = tz.getTimeZone(
javaCast( "string", arguments.timeZoneID )
);
// Get the offset for the timezone
var tzOffset = tzInfo.getOffset(
javaCast("long", 0)
);
// Get the offset hours
var tzOffsetHours = tzOffset / 3600000;
//Check if the timezone is observing DST
var inDST = tzInfo.observesDaylightTime();
var tzOffsetHoursDST = inDST ? tzOffsetHours + 1 : tzOffsetHours;
//Return
var offset = {
inDST = inDST,
timeZone = arguments.timeZoneID,
offsetMillis = tzOffset,
offsetHours = tzOffsetHours,
dstOffsetHours = tzOffsetHoursDST,
timeZones = (arguments.returnTimezones)? tz.getAvailableIDs(): [] //Allow the user to return all the timezones (optional)
};
//writeOutput(tzOffset / 3600000);
return offset;
}
tzID = "America/Denver";
//tzID = "America/Phoenix";
//tzID = "America/Los_Angeles";
offset = calcTZOffset(tzID, false);
//Dump out the results
writeDump(var=offset);
</cfscript>
This should give you the UTC offset in hours. I know it works in Lucee but should in ACF also.
var timeZone = getTimeZoneInfo("America/Phoenix");
WriteDump(timeZone.utcHourOffset);
I want to find the solution time of my model in CPLEX and I used the following code:
float temp;
execute{
var before = new Date();
temp = before.getTime();
}
// solve the model
execute{
var after = new Date();
writeln("solving time ~= ",after.getTime()-temp);
}
But the result is : 1.5592e+ 12, which is a huge number. So, do you know how can I reach to the the solution time in second or millisecond?
This is more of a pure javascript question rather than something related to CPLEX. The number you're getting is in milliseconds, but you can convert that into seconds, minutes, etc. using the techniques described at stackoverflow.com/questions/41632942. For example:
var timeDiff = after.getTime() - temp;
// Convert from milliseconds to seconds.
timeDiff /= 1000;
// Display diff in seconds.
writeln("solving time ~= ", timeDiff);
Making a countdown app and instead of manually adding the due date i want to be able to do it with a date picker.
Here is the code i am using now. What i need help with is implementing code that let's me do this by using the date picker (The competitionDate).
// Here we set the current date
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Hour, .Minute, .Second, .Nanosecond], fromDate: date)
let hour = components.hour
let minutes = components.minute
let month = components.month
let year = components.year
let day = components.day
let currentDate = calendar.dateFromComponents(components)
// here we set the due date. When the timer is supposed to finish
// final Calendar value
let userCalendar = NSCalendar.currentCalendar()
let competitionDate = NSDateComponents()
competitionDate.year = 2015
competitionDate.month = 6
competitionDate.day = 21
competitionDate.hour = 08
competitionDate.minute = 00
let competitionDay = userCalendar.dateFromComponents(competitionDate)!
// Here we compare the two dates
competitionDay.timeIntervalSinceDate(currentDate!)
let dayCalendarUnit = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Hour, NSCalendarUnit.Minute], fromDate: date)
you mean to get the date of the date picker?
you can do it like so:
let date:NSDate = datePicker.date
I have one kind of scenario using date picker. I have date picker with max date=current date + 10 days,on page load only i want to show date more than the max date,but I'm allowing user to enter only up to max date. Is it possible. Without looking maxing date i want to display only the date what ever i want.code:-
var datepicker = $("#date" + uid).data("kendoDatePicker");
var addDays = new Date();
if (arr[1] == "") {
var d = new Date();
datepicker.min(new Date());
datepicker.max(new Date(d.getDate() , d.getMonth(), d.getDate()+ parseInt(arr[1]) - parseInt(1)));
}
I don't know if this is achievable. But what if you try to add two date pickers instead? One that display only the text, and the other only the calendar button. You need to play a bit the CSS, but I think it could spare you a lot of time.