Javascript Editing Hours [on hold]

hours = ["3:42am", "6:37pm", "1:24pm", "2:11am", "8:30am", "1:51am", "12:03am", "11:18pm", "12:28pm", "3:46am", "10:27pm", "9:47am", "12:07am", "8:28pm", "8:41am", "10:43pm", "11:55pm", "10:57pm", "12:43pm"] function SplitHours(hours) { let hourObject = {} let hour = [] let minute = [] let hourPeriod = [] let i for (i = 0; i < hours.length; i += 1) { hour[i] = parseInt(hours[i].match(/^[^\:]*/gi)[0]) minute[i] = parseInt(hours[i].match(/[^:]*(?=pm|am)/gi)[0]) hourPeriod[i] = hours[i].match(/([A-Za-z])\w+/gi)[0] if (hourPeriod[i] == "pm" && !(parseInt(hour[i]) == 12)) { hour[i] = parseInt(hour[i]) + 12 } hour[i] = minute[i] > 30 ? hour[i] + 1 : hour[i] if (hour[i] == 13 && hourPeriod[i] == "am") { hour[i] = 1; hourPeriod[i] = "pm" } else if (hour[i] == 13 && hourPeriod[i] == "pm") { hour[i] = 1; hourPeriod[i] = "am" } } hourObject.hour = hour return hourObject }

I am just trying to rewrite hours; say 1:24pm, if 24 > 30 then it is 2pm, otherwise it is 1pm.

I really doubt that I am doing it right, first I am sure it looks so amateur, second I am not sure if it is optimised.

Can you provide me a better approach to this?

This is also on: as I am not sure where this belongs to.

Category:javascript Views:32 Time:2019-03-07

Related post

  • WPF Edit hours and minutes of a DateTime 2010-05-21

    I have 3 TextBoxes to edit a DateTime. What is important to notice is that those 2 TextBoxes are editing the hour and minutes of the first TextBox DateTime value. One to edit the Date and 2 to edit hour and minutes. How would you do that? The code be

  • Javascript 12 Hour to 24 Format convertor 2011-04-19

    Is there any way i could convert a 12hour time format into a 24 hour format in JS? I'm not that good with JavaScript at all so still surprised i could manage to get even this far. What i'm trying to do is convert time from 12 hour to 24 hour so i can

  • Looking for web-based graph editing framework [on hold] 2009-08-25

    Does anyone know of a web-based framework for interactively editing graphs (nodes and edges)? Flash or Javascript is fine. I'm looking for something like GEF in Eclipse, or JGraph, or the NetBeans graph framework. Thanks! Just to be clear, I'm intere

  • JavaScript setInterval loop not holding variable 2010-03-14

    Here is my code: var showNo = 1; window.setInterval(function() { console.log(showNo); if(showNo === 1) { var nextNo = 2; } else if(showNo === 2) { var nextNo = 3; } else if(showNo === 3) { var nextNo = 4; } else if(showNo === 4) { var nextNo = 5; } e

  • What workflow should I use for JavaScript editing? 2010-04-21

    Warning: I have very little JavsScript experience. In my past programming experience, I usually have a standalone interpreter/compiler, a text editor and a command line to compile/run my software or my tests (I love test driven development). I really

  • javascript editing prompt 2010-07-28

    I am creating a web application in which i have to show an editing prompt when user wants to navigate from the page. I want to only show this when users had edited some value on that page and he does not save the changes then the prompt will ask "Do

  • Sharepoint - display bug in javascript edited newform.aspx ( wss 3.0 ) 2010-08-06

    I took the generated newform.aspx file that has a select-field with 3 options. I now added some js/jquery code to display different fields for options 1/2/3 by taking the internal field name of the select-field and looking up what option is selected

  • In JavaScript, can I get hold of the node that script is enclosed in? 2011-01-05

    Is there any way in JavaScript to get hold of the parent node of the currently executing script node without have an id attribute on the script tag? To illustrate what I mean, if I want to append an img to the document, and I want to append that imag

  • Eclipse questions for a Visual Studio programmer (using Javascript Edition + pydev) 2011-04-17

    I am new to eclipse and am using it for Google App Engine development. I come from a Visual Studio background. I installed following edition of eclipse from this link: Eclipse IDE for JavaScript Web Developers. Version: Helios Service Release 2 Build

  • javascript editing fields after manual edit of field 2011-04-28

    I've looked everywhere on this. basically what I have is a script that changes the value of some fields based on a radio selection. For example: Think of it like a radio button that gets credit card data. it works initially when the page loads and se

  • Javascript current hour to use specific stylesheet? 2011-05-03

    I use the following code to get the current hour of the client and to know if it's AM or PM: <script type="text/javascript"> //get client time var d = new Date(); if(d.getHours() >= 06 && d.getHours() <= 18){ var dayStatus = "day"

  • In-place Javascript editing addon 2011-06-11

    Is there any inplace editing addon for Javascript..something like firebug which is very useful for Instant CSS editing and preview, but does not allow inplace JS editing..So, is there any tool or addon where we can instantly update and see Javascript

  • In Browser Javascript editing in FireBug ? 2012-01-25

    we have all luxury with Firebug , Editing Html (In-Browser ) , CSS (In-Browser ) , But if any one working with javascript , each and every time JavaScript file has to be edited and Refresh the browser . Can we not have the such facility with Javascri

  • Live Javascript edit in Safari? 2012-03-20

    In Chrome this is possible, but I don't find a way to do it in Safari. Is it possible? How? --------------Solutions------------- Currently this is not possible. Although both chrome and safari use webkit as their engine, chrome makes its own customiz

  • winXP tablet edition: "press and hold" COMPLETE FAIL 2012-12-20

    hi, I am running WindowsXP Tablet Edition on my Fujitsu Lifebook P1620, which for the most part is great, BUT!!! the "press and hold" action with the pen NEVER WORKS, ever, no matter what I do. Does anyone else with XP tablet edition and a no-button

  • JavaScript edit-inplace-holders which work with Wiki sources 2008-12-01

    I'd like to dynamicly parse in text wiki-content. I found JsWiki but its in beta form, and looks like with no community even developers). Any other? --------------Solutions------------- It depends what you mean by wiki content. There are many wiki fr

  • Javascript: Edit a preview with jquery 2010-08-11

    I have 2 divs, the first one has the label with the content to show, but when you click the "edit" button, it should show you the div="edit" and the content of the 1st label inside of the input that is linked to it (same id). By the other way, I saw

  • javascript, edit code image value checker 2011-03-08

    This code i put it in the HTML page for check the file value, and I want to add some secure values in the code I need to edit this code: <script> window.onload = function () { var form = document.getElementById('forms'), imageInput = document.g

  • Can local JavaScript edit/save files on same local machine? How using jQuery? 2011-06-29

    I'm building a little locally run CSS driven site map for auditing a huge intranet site. I've already coded the ability, to bring up a context menu which provides for options to make updates to the DOM of index.html. I would like to save these change

  • how much data can javascript in the browser hold? 2011-11-09

    I have created a JSFiddle to see how much data I can push into my browser. The link is The code is simple. It's just trying to push as many strings as possible into an array. The strings have an approximate length of 300-31

  • JavaScript editing the URL like facebooks rewriting without hash # 2011-12-14

    You have to use a hash to edit the url in anyway, but how can facebook not use the hash and still change the url? So i am in the process of writing a new photo gallery. I need to be able to perm link each photo, whilst obviously changing the image. M

  • Saving javascript edited image with php 2012-02-21

    I've been looking at this js image processing library, How can I save the new image with php? Is it even possible? --------------Solutions------------- You could try posting the image from the client to the server using JavaScript. This

  • Page DOM doesn't update after javascript edit 2012-03-31

    I've got this example page where I'm trying to put the wmode of every youtube element inside the page to "transparent". With Chrome and its inspector I notice that my javascript works but the browser view doesn't update and the overlay still is under

  • javascript edit: how to disable a css class and add other when current? 2012-03-31

    <script> $(document).ready(function() { $('a.panel').click(function () { $('a.panel').removeClass('selected'); $(this).addClass('selected'); current = $(this); $('#slidewrapper').scrollTo($(this).attr('href'), 300); return false; }); $(window).

Copyright (C), All Rights Reserved.

processed in 0.163 (s). 11 q(s)