View unanswered posts | View active topics It is currently Sun Apr 20, 2014 9:51 am



Reply to topic  [ 29 posts ]  Go to page: Previous  1, 2
 Convert Military Time to Standard Time? 
Author Message

Joined: Oct 17, 2004
Posts: 1162
Location: Rochester, Ny
Post Re: Convert Military Time to Standard Time?
ckeyes888 wrote:Came across another issue. I have a trigger that turns on the hot tub and calculates
what time the tub will reach the desired temp based on it's current temp.
I simply take the military time and add time to it depending on the current hot tub temp.

Problem is that the new number can be outside the military time spec by going over 59 mins.
e.g. if the military time is 1550 and I add 30 mins it becomes 1580, then when I convert that
using the script above the ready time becomes 3:80 pm.


The problem here, is that this isn't a military time problem. You would have the same issue with standard time.

new_datetime = datetime.datetime.now() + datetime.timedelta (minutes=45)

So convert from 24 hour time to standard, and use the above as a template...

_________________
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33


Fri Nov 11, 2011 8:42 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Thanks, but I only know enough AS to get me in trouble.
Could you elaborate some on how to use that bit of code?

Carl


Sat Nov 12, 2011 12:53 am
Profile

Joined: Oct 17, 2004
Posts: 1162
Location: Rochester, Ny
Post Re: Convert Military Time to Standard Time?
ckeyes888 wrote:Thanks, but I only know enough AS to get me in trouble.
Could you elaborate some on how to use that bit of code?


Sorry, my bad, I forgot this thread was referring to Applescript. I gave you Python code...

Date-/Time-Calculations using AppleScript from http://erikslab.com/2007/11/26/date-tim ... plescript/

This short how-to explains how you calculate with time- and date-values in AppleScript. Quite a few people told me, that they are using the do shell script-handler presented in the post How to convert an “epoch”-time to a meaningful date and time. Nothing wrong with that, but if you just want to perform time-calculations inside an AppleScript, then there is an easier way.

If you assign the current time to a variable as in set myDate to current date and you just want to calculate the current date plus 2 days, then there is no need to use epoch-seconds.

set myNewDate to myDate + (2 * days), adds 2 days to the date and time stored in myDate.
set myNewDate to myDate + (4 * hours), adds 4 hours to the current time and date.
set myNewDate to myDate + (30 * minutes), adds 30 minutes to the current time and date.

It is really that simple, AppleScript uses epoch-seconds to perform these calculations, so you don’t have to.

If you need to set the date and time to the beginning of the current day, then use

set myTime to time of myDate

set myNewDate to myDate - myTime

The variable myNewDate now contains the current date and 00:00:00 as time.

_________________
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33


Sat Nov 12, 2011 6:25 am
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Thanks. Guess I'm still not getting this.

I have a time variable "ClockTime" that reads 11:18 am that I'm trying to add time to.
Been trying variations of your post above but no go yet.

set the value of variable "HotTubReadyTime" to (value of variable "ClockTime") + (30 * minutes)

The error is, "Can't make 11:18 am into type number". Makes sense as it's not just a number.

Any help?

Thanks,

Carl


Sat Nov 12, 2011 9:33 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 8356
Location: Austin, Texas
Post Re: Convert Military Time to Standard Time?
Code: Select all
 set the value of variable "HotTubReadyTime" to ((date (value of variable "ClockTime")) + (30 * minutes)) as string

_________________
Jay (Indigo Support)
Image


Sat Nov 12, 2011 1:48 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Thanks Jay. That works great albeit it returns "Saturday, November 12, 2011 6:46:00 PM".
Anyway to shorten that to just " 6:46 PM"?

Carl


Sat Nov 12, 2011 2:50 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 8356
Location: Austin, Texas
Post Re: Convert Military Time to Standard Time?
Code: Select all
 set the value of variable "HotTubReadyTime" to time string of ((date (value of variable "ClockTime")) + (30 * minutes))


That may show seconds - if so, open your System Preferences, open the "Language & Text" preference pane, click on the "Formats" tab, click the "Customize..." button under "Times", and change the "Medium" time format - that's the one that AppleScript uses when "time string" of a date is asked for. Just remove the seconds and the extra colon after the minutes.

_________________
Jay (Indigo Support)
Image


Sat Nov 12, 2011 5:30 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Actually, I was hoping for just the time, not the month date etc.
Can that be done?

Thanks,

Carl


Sat Nov 12, 2011 5:46 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 8356
Location: Austin, Texas
Post Re: Convert Military Time to Standard Time?
Did you try the last one I posted?

_________________
Jay (Indigo Support)
Image


Sat Nov 12, 2011 7:31 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
I did. It returns the full month date and year. Works for me....just curious if it can
just be the time.

Thanks,

Carl


Sat Nov 12, 2011 10:15 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 8356
Location: Austin, Texas
Post Re: Convert Military Time to Standard Time?
The last one should only return "11:00:00 pm" (or something similar - it definitely should not return any of the date). Not sure why it isn't working for you. Make sure you got the last one that includes "time string" - maybe you didn't copy/paste it in correctly?

_________________
Jay (Indigo Support)
Image


Sun Nov 13, 2011 12:18 am
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Doh! must have missed copied it. Easy to lose the seconds to just show 11:00 am?

Many thanks,

Carl


Sun Nov 13, 2011 12:11 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 8356
Location: Austin, Texas
Post Re: Convert Military Time to Standard Time?
Read the rest of the post that has the script in it... :P

_________________
Jay (Indigo Support)
Image


Sun Nov 13, 2011 2:58 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 1340
Location: Kalispell, MT
Post Re: Convert Military Time to Standard Time?
Doh...again. I'd just set it to short. Maybe some day I'll learn to read.

Thanks,

Carl


Sun Nov 13, 2011 3:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 29 posts ]  Go to page: Previous  1, 2

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.