Converting 24 hour clock to 12 hour clock using JS

How do I change the format of the time?  Currently the time is based on a 24 hour clock.  I'd like to have a 12 hour clock with am/pm designations.  Here is the JS:
//first lets get the current time by parsing the title from the data query
                            var timeIndexStart = data.query.results.channel.item.title.lastIndexOf(' at ') + 4; //4 is the size of the string " at " (whitespace included)
                            var timeIndexEnd = data.query.results.channel.item.title.length - 4; //4 is the number of characters from the end of the string (1 space + time zone)
                            var timeZoneStart = data.query.results.channel.item.title.lastIndexOf(" ") + 1;
                            //lets go ahead and store the time now
                            //format = "Conditions for "city", "state" at [time] [time zone]"
                            var time = data.query.results.channel.item.title.substring(timeIndexStart, timeIndexEnd);
                            var timeZone = data.query.results.channel.item.title.substring(timeZoneStart);
                            var d = new Date();
                            var localTime = d.getTime();
                            var localOffset = d.getTimezoneOffset() * 60000;
                            var utc = localTime + localOffset;
                            var currentTime;
                            if (options.relativeTimeZone) {
                                var timeByLocation = new Object();
                                timeByLocation["EDT"] = utc + (3600000 * -5);
                                timeByLocation["EST"] = utc + (3600000 * -5);
                                timeByLocation["CDT"] = utc + (3600000 * -6);
                                timeByLocation["CST"] = utc + (3600000 * -6);
                                timeByLocation["MDT"] = utc + (3600000 * -7);
                                timeByLocation["MST"] = utc + (3600000 * -7);
                                timeByLocation["PDT"] = utc + (3600000 * -8);
                                timeByLocation["PST"] = utc + (3600000 * -8);
                                timeByLocation["HST"] = utc + (3600000 * -10);
                                timeByLocation["AKDT"] = utc + (3600000 * -9);
                                timeByLocation["AKST"] = utc + (3600000 * -9);
                                currentTime = timeByLocation[timeZone];
                            else {
                                currentTime = localTime;
                            var today = new Date(currentTime);
                            var dstOffset = 0;
                            var hourMod = "";
                            var minMod = "";
                            var background = "";
                            if (today.dst())
                                dstOffset = 1;
                            if (today.getHours() + dstOffset < 10)
                                hourMod = "0";
                            if (today.getMinutes() < 10)
                                minMod = "0";

Does this help?
javascript source code: 12 hour clock
Thanks,
Preran

Similar Messages

  • The server clock on a website I use is 5 hours behind. When I use Internet explore, the time is correct.

    The server clock on a website I use to make t-times (FORETEES) is 5 hours behind the current correct time. The time has always been correct until this morning. It is necessary for the server clock on this web site to be the same as my current time. I used IE to get into the FORETEES web site and the clock was correct on the FORETEES web site. What happened between yesterday and today on the Foxfire servers...

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > Cookies: "Show Cookies"

  • [SOLVED] Gnome clock is 2 hours off hardware clock

    hi, i'm not sure if this is the right place to post but here we go..
    I've just installed arch on my laptop and now everything seems to work pretty well, although the clock in gnome/cinnamon is 2 hours off hwclock/localtime. Does anyone have a suggestion how to fix this? I don't seem to be able to edit it manually through the gui
    Last edited by frmi (2012-08-21 15:29:45)

    2ManyDogs wrote:
    When you did the install, did you do this step: https://wiki.archlinux.org/index.php/Be … clock_time
    frmi wrote: the clock in gnome/cinnamon is 2 hours off hwclock/localtime
    Does this mean your hardware clock is set to loacal time?
    What does
    sudo hwclock
    return (and is that local time)?
    and what is in /etc/adjtime?
    This just made me realise that it's the hwclock which is off localtime.
    Would
    # hwclock --systohc --utc
    Set the clock properly or should i use localtime instead of utc?
    anyway here's the output:
    [fm@fm-lap ~]$ sudo hwclock
    Password:
    2012-08-19T15:39:23 CEST -0.145579 seconds
    [fm@fm-lap ~]$ cat /etc/adjtime
    0.000000 0 0.000000
    0
    UTC
    Last edited by frmi (2012-08-19 11:50:01)

  • History wont update unless i set my system clock ahead 3 hours

    I have uninstalled and reinstalled firefox but nothing i do works. The history will only start working if i set my clock ahead 3 hours. Any way to fix that besides setting myself to a different time zone that's 3 hours behind me.

    Hi brotheryang17,
    I asked qa and there are some more steps to take to make sure that it is not an add on affecting the functionality of bookmarks. The two suspicious one are Ad Block or Ghostery, however it could be a combination as well.
    To run an experiment we can try two things: disabling each of the add ons one at a time to make sure that it is not an add on, or can try to create a new profile temporarily and add a bookmark with the time normally set.
    [[Troubleshoot Firefox issues using Safe Mode]] and [[Use the Profile Manager to create and remove Firefox profiles]]

  • Forgot to set camera clock back an hour.  How do I batch the time?

    I forgot to set my camera clock back one hour, and I need the files to read the actual time it was. So, basically, everything shot is off by one hour exactly.
    It all is imported into my library already. How can I adjust the time so it falls back one hour for each file?

    Thanks! That was easy

  • How to stop hourly alarm like a cuckoo clock

    My MacAir all of a sudden starts to go off like a cuckoo clock on the hour of each hour.  How do I stop it.  My daughter thinks that I must have accidentally hit some keys to enable this function,  Now I just want it to stop

    My suspicion is still that this is caused by some software you have installed. One thing to do would be to generate a system profile via EtreCheck, paste the output here, and maybe someone can spot what software might be generating this sound.

  • Since upgrading to Mavericks I am finding that I am lucky to get 2 hours (when connected to WiFi) of use from my macbook Pro.

    Since upgrading to Mavericks I am finding that I am lucky to get 2 hours (when connected to WiFi) of use from my Macbook Pro.  I have turned off Bluetooth ( which was not an issue previously), uninstalled Chrome, again not an issue before I upgraded, and have not seen any improvement.
    I was using an older OS system (Snow Leopard) on my 2010 Macbook Pro.  I am wondering now if the upgrade was an unwise move?

    jbuckworth,
    which apps do you run under battery power? Are any of them identified as “apps using significant energy” when you click on the battery icon in the menu bar? If you have a 15-inch or 17-inch model, are your apps using the discrete GPU (which consumes more power than the integrated GPU)?
    How many charge cycles has your battery accumulated?
    How long have you had Mavericks installed? Is Spotlight still reïndexing your boot drive? (It does that whenever your OS is upgraded, because so many files change in an OS upgrade.)

  • I am trying to add a video to my Keynote presentation on my iPad. Since I am 2 hours away from my computer to use iTunes. Is there a way to move videos to the camera roll so I can use them?

    I am trying to add a video to my Keynote presentation on my iPad. Ideally I would like to be able to play the video in the presenation sream rather than switch between apps. Since I am 2 hours away from my computer to use iTunes syncing to move them there is not an option. Is there a way to move videos already on the iPad to the camera roll on iPad 2so I can use them?

    iOS: Importing personal photos and videos from iOS devices to your ...

  • My pic 3 has suddenly started draining the battery in only a few hours even when I am not using it. Might this mean something is running all the time? I recently downloaded Dropbox. How do I check? What do I do about it? Or is battery faulty? Tim

    My ipad 3 has suddenly started draining battery in only a few hours. Even if not in use. Might this be because a programme is running in he background? I recently downloaded Dropbox. Might my photos still be downloading after a few days? How do I check? What do I do about it? Or might my battery be faulty? Thanks, Tim.

    Using the battery level meter in this manner is comparable to using your car's fuel gauge to calculate miles per gallon.  The only thing that matters is the total amount of operating time from full charge to auto-shutdown.
    Use the wall-mount charger that came with the iPad and charge overnight.  Admittedly the labeling is hard to read but, if you use a magnifier and squint your eyes, you'll see "Output 5.1V, 2.1A."  The symbol between volts and amps is the symbol for DC.  Do NOT use an iPhone charger.  Do NOT use an iPod charger.  Then, operate it normally until auto shut-down (ignore any low level alerts that may appear).  An irony is that doing that test to determine the total operating time is also the exact procedure necessary to calibrate the battery level meter.
    I'm not claiming that you do not have a problem.  I am stating, however, that we don't yet know whether or not a battery problem exists.
    According to Apple:
    Use Your iPad Regularly
    For proper reporting of the battery’s state of charge, be sure to go through at least one charge cycle per month (charging the battery to 100% and then completely running it down).
    Elsewhere, Apple elaborates and explains that two half-discharges (or four quarter-discharges, etc.) equals one full discharge.

  • Hi there i have issue in mavericks i thing so because now in 80% the battery shows it has 3 hours and 5 minutes left only using safari and mail....

    hi there i have issue in mavericks i thing so because now in 80% the battery shows it has 3 hours and 5 minutes left only using safari and mail....is there any fix or update.....help appreciated....

    Is the MacBook/Air still covered under any AppleCare plan?
    If you are in the US or Canada, the Apple Store with Genius
    bar can have a look at it, and diagnose it for free; you'd have
    to set an appointment at a store nearest you, for them do do it.
    Not sure how old the unit is or how it was used, charged, or re-
    charged; but those are the kinds of little things that may affect
    battery life or subtract possible useable Cycles off its life.
    Some users of MB/Air models (and MB/Pro, etc) had noticed
    a loss of battery capacity after an upgrade to Mavericks. So
    that may be some kind of revision to how the battery is seen
    by the newer OS X. No idea if Mavericks uses more power.
    To see an expert or specialist about this issue, for advice, &
    or test/diagnose may be an idea. Could be it needs a new
    battery. How does the rest of the battery/power specs look?
    Perhaps the MacBook just wants to get out on the town...

  • Hello i have a problem that i was making update IOS7 for my i phone 5 it's taking a lot of time about 4 hours till now, i can't use my phone know, it's appere logo i tunes only, can't do eny thing else like shutdown

    Hello i have a problem that i was making update IOS7 for my i phone 5 it's taking a lot of time about 4 hours till now, i can't use my phone know, it's appere logo i tunes only, can't do eny thing else like shutdown

    Hey Andrew keriakous,
    Thanks for the question. It sounds like your iPhone may be in recovery-mode. To resolve this issue, see the following:
    If you can't update or restore your iOS device
    http://support.apple.com/kb/HT1808
    Thanks,
    Matt M.

  • Hi i received the nano 7th gen for Christmas and I only seem to get 5 hours of battery life. I use the Bluetooth and Nike app so I expect more drain on the battery.  But I got more time out of running with my iPhone. Does this sound normal? I thought I sh

    Hi i received the nano 7th gen for Christmas and I only seem to get 5 hours of battery life. I use the Bluetooth and Nike app so I expect more drain on the battery.  But I got more time out of running with my iPhone. Does this sound normal? I thought I should get close to 30 hrs of just play time alone.
    ALso, my wife got me the Belkin armband to run with the nano but I sweat through the band resulting in the back of the iPod to get wet. Surely this is not good. Anyone have a recommendation for an armband that keeps moisture away from the pod?

    iPod Nano are small and they don't use Wi-Fi access so you get less power time on a Nano. As for iPhone, since you got apps, Wi-Fi + 3G access, and everything else, they give you more time so you can keep using. Nanos are ment to listen to music, listen to radio, view your photos, watch videos (without Wi-Fi) and since you got BlueTooth on the nano, it counts as wireless access so it drains your battery faster.

  • Output clock on general data pins using 6536?

    Hello,
       I have an NI PCIe-6536 DIO card, using latest DAQmx drivers, using C language.
       I would like to output the sample clock (or other clocks) on a few general DIO pins, like port0/line3 and port1/line6.
       What's the best way to accomplish this?  Is it best to use Task-based or 'independent' signal routing?  Am I missing a code example that will make my question seem even dumber?
       This seems to work when I try to connect to PFI4:
    DAQmxErrChk (DAQmxConnectTerms("/Dev1/DO/SampleClock","/Dev1/PFI4",DAQmx_Val_DoNotInvertPolarity));
      However when I try to also connect that terminal to port0/line3 I get an error:
    DAQmxErrChk (DAQmxConnectTerms("/Dev1/PFI4","/Dev1/port0/line3",DAQmx_Val_DoNotInvertPolarity));
    Destination terminal to be routed could not be found on the device. Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer or your hardware documentation for valid terminal names. Source Device: Dev1 Source Terminal: PFI4 Destination Device: Dev1 Destination Terminal: port0/line3 Status Code: -89121
       This error sounds like a trivial terminal name issue, but I'm fairly sure the terminal name is Ok.  Am I wrong?
    I have tried another method using task-based signal routing and DAQmxExportSignal, which also returns an error:
    DAQmxErrChk (DAQmxCreateTask("",&clockTask));
    DAQmxErrChk (DAQmxCreateDOChan(clockTask,"Dev1/port0/line3","SCLK",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxExportSignal (clockTask,DAQmx_Val_SampleClock, "/Dev1/port0/line3"));
    DAQmxErrChk (DAQmxStartTask(clockTask));
    Sample Clock Output Terminal requested is not supported given the requested Timing Type. To use the requested Timing Type, do not set the Sample Clock Output Terminal property. NI-DAQmx automatically selects a compatible Sample Clock Output Terminal. To use the requested Sample Clock Output Terminal, select a different Timing Type. Property: DAQmx_SampTimingType Requested Value: DAQmx_Val_OnDemand Property: DAQmx_Exported_SampClk_OutputTerm Requested Value: /Dev1/port0/line3 Task Name: _unnamedTask Status Code: -200910
      I'm guessing my port0/line3 needs to be configured differently, but I'm not sure which timing type to set.
    So my question is if this is even possible, I'm just doing it wrong?   Or is it true that I can only output a clock on PFI4 and PFI5 pins?
    As a follow up, should I instead be using the following function to export the sample clock?
    DAQmxErrChk(DAQmxSetExportedSampClkOutputTerm(taskHandle,"/Dev1/PFI4"));
    Also I see these functions: 
    DAQmxSetExported10MHzRefClkOutputTerm
    DAQmxSetExported20MHzTimebaseOutputTerm
    Can I use these to output to port0/line3 and port1/line6?   I have some flexibility in clock speeds I can use, but curious if I can output 3 different clock speeds?
    Also I could work out a method to use external clocks from other devices, but would prefer to maximize my usage of the internal clocks on the 6536 to keep the hardware requirements as simple as possible.
    Thanks so much for any advice or insights!

    Hi ghardy,
    I recommend using task-based signal routing because of its organization. I would probably use the DAQmxExportSignal function to export the sample clock to D I/O ports. You can read more on exactly how to configure it here.
    http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxexportsignal/
    You can use this function both internal and external device signals. Hopefully this helps.
    Paul C
    Paul C
    Applications Engineer
    National Instruments

  • Dashboard Clock Widget like iPhone Clock

    I've had an iPhone for a couple of years, and this week I'm finally making the switch from PC to Mac. One of the really simple questions I have is where to find a clock widget for the dashboard that functions like the iPhone clock with time zone clocks, timer, and alarms. Everything I've managed to dig up so far is too bloated for simple daily tasks like quickly checking what time zone a client is in before calling. Is there anything out there someone can recommend that is as easy to use and straightforward as the iPhone clock app except for the dashboard?

    Actually if you want to do a bit of tinkering you can change the clock face to ANY city town or village you likr just follow this link
    http://www.macosxhints.com/article.php?story=20050430193250534

  • Averaging over the last hour and last eight hours.

    This is fairly simple but I'm not sure what a "good" approach is. Basically I need to track how many times a user has performed an action over the last hour and last eight hours. I'll receive a notification of some sort when they perform this action and could get the current time, but I'm not sure what a fast way of determining how many times this has occurred in a given time period is.
    I was thinking perhaps an array with the time of each in milliseconds and just find the first index that was < 8 hours or < 1 hour ago and then subtract the index from the current size. I think that would be problematic though. To keep the array from continuously growing I'd have to shift everything over to the left which means an expensive arraycopy. Perhaps if I only did the resizing when there were > 20 or elements I no longer care about or something would help, but then I'd have to iterate over 20 elements I don't care about everytime it's calculated, which is once a second.
    Any algorithms that will solve this?

    Here is a method with a granularity of a minute (i.e.
    it only updates the average value every minute - you
    can change it to give whatever granularity you want)
    Keep an array with 60 elements in it. The array
    counts the number of times that the user performed
    the action each minute.
    The array in indexed modulo real time, and you make
    entries based on actual time of day. So when a user
    performs an action at 8:38:45 you increment slot 38.
    Each slot counts the number of actions that took
    place in that particular minute. When the next minute
    rolls around, you move to the next slot, set the
    value to zero (thus throwing out the events that
    happened over an hour ago, and prepare to count the
    new events)
    The sum of the entire array is of course the total
    number of events that have taken place in the last
    hour.
    You do not need to actually run through the array and
    total the events every time you want to calculate the
    average. You can use the fact that you increase the
    total by one every time you get a new event and you
    decrease the total by X everytime you zero out a slot
    that had X for its event count.
    So you can just keep a single value, Total, along
    with your array that goes up by one on every event
    and then drops back a little every minute, when you
    throw out the hour old events.That is probably a good solution to the question I posed, but I realize now I was not thorough or accurate enough in describing the context and requirements. I don't think that will work without a lot of unnecessary memory, but maybe I'm wrong.
    The user action is actually the successful completion of entering a form, a bill to be more precise. I expect this to happen 100-300 times an hour to give an idea of the frequency. Given a period of time, if they've been at it for that period of time or longer I need to find the number of bills completed in that most recent period of time. Otherwise, I need to use what is available to predict what they will reach in that period of time. In other words, if the time period is an hour I need to figure out how many bills were completed in the last hour, but if they've been going for only five minutes I need to predict what they will have completed in an hour including those last five minutes. Then I need to do the same thing for seven hours, using the last seven hours or less of data.
    I guess I'd just have to use a granularity of a minute or less and calculate how many bills over how many minutes and make a prediction on that? I suppose I was hoping for something more precise, but now that I think about it that will probably suffice.
    How would you implement it though? Create a "minute" array of size 60 initially, then when reaching the end of that array adding the total for that array to an "hourly" array (keeps track of bills in that hour) and then start over? I guess then you'd just have to add each from the hourly array to the current total and calculate based upon that. At any given time I'd have the number of bills processed in the last x hours and y minutes, which is enough to calculate how much can be completed at that rate in a given hour or seven hour day.
    I'll try this tomorrow when I get to work, thank you very much I was needlessly complicating it with timestamps. In fact, this inadvertently (or perhaps purposefully?) solves an issue with not calculating time when a user is at lunch or on break. At least I think it does.

  • Can you make a spreadshee​t object log every hour on the half hour?

    I have a spreadsheet object that logs the data every hour on the hour, i.e., at 1:00 p.m., 2:00 p.m., etc. Can I make it log every hour on the half hour, i.e., at 1:30 p.m., 2:30 p.m., etc.? If so, how?

    Hi,
    Yes you can make the spreadsheet object to behave in that way by just using with it the TimeOfHour object.
    The TimeOfHour object output goes high every hour at some offset into each hour. So is just a matter of defining the offset as being half an our and placing the output of this object in the yellow field "Log now=" of the Spreadsheet object.
    You can leave the "Interval=" and "Logging=" field empty since the "Log now=" will override them.
    I hope it helps
    Andre Oliveira

Maybe you are looking for

  • Help-multiple ipods on one computer

    my husband and i each have an ipod with seperate user accounts on itunes. we would like to open his ipod on my computer and bring up all his songs without overwriting or adding my songs to his. does anyone know how to do this?

  • Need to "publish/subscribe" my Contacts info like we could in Addressbook. Any ideas?

    Being a LONG TIME Mac User (yes, I owned a Lisa in the early 80’s and it still runs!)  I have lived thru the transition from OS 6 and 7, then 8, 9 and finally the upgrade to OSX and thru its incarnations up to my current Maverick (aka OS 10.9.4).  I

  • HT4623 update ipad with ios 4.3

    how do I update ipad with ios 4.3

  • Eingefügte Kreise aus Zwischenspeicher wandern nach re unten. Wie abschalten?

    Hallo, mit Professional habe ich ziemliche viele Ereignismeldungen die mir als pdf vorliegen zusammen gefügt. Nun will ich bei allen Seiten an der selben Stelle einen Eintrag mit einem Kreis umranden. Um den ersten Eintrag auf der ersten Seite ziehe

  • Update error U41MIC212

    photoshop elements 11. everytime i try to update an error message shows up U41MIC212 and will not allow access. i have tried with and without firewall switched on, is the server down or what? what can i do to get this service working. i have just pur