Java script - adding times [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to add two times in this format:
HH:MM:SS
eg: 12:31:32 and 01:32:39
I want to write a script that adds times and the result of which must be in the same format.
How would you tell the script to add up the first two digits before : (hours) and then the two between the two semicolons (minutes) and then seconds?
I don't want anyone to make the script I just want to know how it could be made.

If they are strings var time1 = "1:23:25" then you will need to convert it into something else to work with it.
You can do it manually, by splitting the string into an array and adding the numbers and handling any overflow (>60 seconds to increase minutes etc) and then joining the hours, minutes and seconds back together to create a new string.
You can also convert each to a Date which you can just add together like they were numbers eg:time3=time1+time2 you can then format the result back into the original format.

Related

Time lapse web interface [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hello and thanks in advance for looking at my problem. I'm trying to create a web interface for a time lapse project I'm doing right now, but I don't know exactly where to start with this.
What I have
A website, obviously;
A lot of pictures, made every 15 minutes;
Stored in folders (/mm-yy), saved as dd-mm-yy_hhmm.jpg.
What I'm looking for
I want to be able to select a date with a datepicker, which returns all the pictures taken on that particular day so I can show only those pictures on the site.
I've been searching around but I have troubles finding out what the best solution is and where to start. I don't have a lot of experience with JavaScript. I thought maybe create a JSON-file with all the images (regenerated every 15 minutes) and use that in some way with a datepicker?
Any ideas, tips and/or tricks?
There are numerous ways to approach this but since you tagged php my first impulse would be something akin to:
Walk the directory tree to find all represented months
For a given month build your date list using regex - this will let you pull out the date matches you need
Create your date picker using one of the many, many javascript options
IIWM I wouldn't mess about with a separate file the gets regenerated. Do your population when the page opens.

Parsing of ISO 8601 time intervals in Javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am building a front end component to allow users to choose a date\time range and optionally use time periods as per the ISO 8601 specification.
The component will need to bind to any existing values already set by the user, and so I am looking at how to parse out the time interval period piece for a string such as:
"2007-03-01T13:00Z/P1Y2M10DT2H30M"
I am unsure how to extract the numerical parts of the time interval piece so I can get some sort of object\array, keyed by the letters perhaps so I can easily determine number of years (Y), months (M), etc.
I could have a go at my own regex, but I suspect someone out there has already done this.
I'm wanting to give users a series of number inputs and just set these for any existing period values the user has set previously.
Can anyone suggest any approaches here?
I hope this makes sense!
Thanks
Try this:
var dateStr = '2007-03-01T13:00Z/P1Y2M10DT2H30M';
var date = new Date(Date.parse(dateStr.split('/')[0]));

Generating random id using current date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm doing a bank oriented project. I have to generate Account Number using current date.
Example:
account no-20150409001.
'2015'-Year,
'04'-Month,
'09'-Date,
'001'-represents the number of the new member opening the account on that particular date
This number should change in every branch to avoid same account number.
How to do so?
and this is my code
http://jsfiddle.net/Jegannath/z9na41o5/#&togetherjs=ynHxlyDeO1
If this is really a bank related project, do not rely on client side JavaScript for something as critical as the account number generation.
Is there a reason for the "random" number requirement? If not, stick with a sequence, it is a lot easier to ensure uniqueness.
On the server side, using a branch prefix as suggested by #kuldeep.kamboj should cover collision.
You can use something like yyyyMMddBBnnnn where yyyy = year, MM = month, dd = day, BB = branch number, and nnnn as a sequence that resets per day.
Not sure,this is correct advise,
Go with branch code prefix and timestamp in suffix, this might be developer friend also, because in future after 30 year easily you can tell his account created date with the help of timestamp.
As well timestamps is kind of random number.
advisable is server side code.

javascript regexp pattern definition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I need help
I have a form feild I need to add validation to. The format of the value has to be specific. I want to define a regex pattern to handle it.
The format needs to allow L123456
L = it has to be L which is the start of out skus
123456 = I need to confirm they are entering a 6 digit number.
thanks
Jeff
var str = "L123456";
/^L\d{6}$/.test(str)
The pattern uses the ^ to determine the strings starts with. \d{6} states 6 digits, and $ means end of string. See: http://www.regular-expressions.info/ for more info.

How to validate time input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have an HTML text box () for input time that is in hh:mm format (h: hour and m: minute). I would like user to input the time in that format. How can I achieve that by using jQuery or some JavaScript codes? Thank you.
There are many jQuery plugins that do input formatting/validation. A tricky part might be to come up with a regular expression that validates correct times. This example is pretty flexible:
^([01]?[0-9]|2[0-3]):[0-5][0-9]$
It allows the first 0 to be optional, and ensures that hours don't go above 23. It also makes sure that the minutes are between 00 and 59.
Depending on how you parse your result, you might want to be more restrictive. For instance, you could remove the ? from the regex to force HH:MM format, and still ensure that hours are between 00 and 23, while minutes are between 00 and 59. It looks like that:
^([01][0-9]|2[0-3]):[0-5][0-9]$
Use this regex to validate time in hh:mm format.
^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
You might have to edit for your specific use case.
Here is a fiddle http://jsfiddle.net/ENz9p/27/
source: How to validate a time user input like hh:mm to hh:mm in javascript?
There are a few ways to do it in js (Date.parse), but I think moment.js is the easiest (most robust) way out there.
http://momentjs.com/

Categories