Can someone please explain how those lines code works? [closed] - javascript

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 2 years ago.
Improve this question
Can someone please explain how those lines code works?

setInterval() executes function over and over. This function:
Declares variable birthday with future date as a reference and
converts it to special format (milliseconds since UNIX epoch)
Declares variable now with current moment converted to same special
format.
Declares variable distance with difference between above two.
That is, distance holds milliseconds left to birthday.
Populates DOM elements (days, hours, minutes, seconds) with time left to birthday
When difference becomes zero, it populates DOM elements (headline) with "It's my birthday" text and makes it visible (sets its style attribute) and at the same time makes counter invisible.

it will continue running while the browser open, and will show :
It's my birthday
on 30 september 2021 at 00:00:00

Related

How can i change the URL string i'm fetching from after each fetch? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
The community is reviewing whether to reopen this question as of 6 months ago.
Improve this question
I need to fetch 12 different nums for every object, and there are 31 different objects.
Basically, the API string ends like this:
/count?publishedAt_gte=2022-01-01&publishedAt_lte=2022-02-01&newsSite_contains=1&_limit=500
'_contains=1' determines the object, =2 will render the next one, =3 the one after and so forth until '_contains=31'
'_gte=2022-01-01&publishedAt_lte=2022-02-01' determines the specific num value, as changing the months (2022-01-01 becomes 2022-02-01 and 2022-02-01 becomes 03..) will return a different num.
So the function should fetch the num value from the base url, push it in a array, then raise the months numbers by 1 and repeat 12 times, to then return at the starting month to change the 'contains' part and raise it by 1 - all of this 31 times. So we'll have 31 arrays, each with 12 nums.
Do you think it's doable, and how?
If it runs with Node you can use the URL module. It has methods to get/set and such for the query params.
If it runs in the browser you can use the URLSearchParams web API.
Regarding implementation, you can tell me the environment this function would be invoked in and I can write something down for you.

display time and date in GMT or UTC [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 2 years ago.
Improve this question
I am trying to display GMT/UTC time with current date LIVE
i can display current time with it will be fixed until did refresh for the page
what i need to do display the time and date in UTC/GMT in my page as PHP or java code
thank you
If you want to convert your current time to another timezone lets say GMT or UTC then you can follow the following steps for javascript:
You can use moment-timezone lib.
const moment = require('moment-timezone')
const now = moment().format()
moment.tz(now, 'UTC').format()
moment.tz(now, 'GMT').format()

Java script - adding times [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 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.

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.

Digital clock in website [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
Can anyone please explain me how to put a digital clock in my jsp page. I have to put two clock one for India and one for Switzerland.
How can this be possible ?
This website has a tutorial on using the Date.getTimezoneOffset() method which you'll be able to use to define the clock locally.
http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/
India is easy- one time zone for the whole country, and no daylight savings time.
India time is UTC+05:30.
Sweden observes dst between 2:00 am on the last Sunday in March and 3:00 am the last Sunday in October.
Sweden's offsets are UTC+1:00 during standard time, UTC+2:00 during dst.
Be sure to apply the dst changes in Sweden's time, which is easy to calculate from UTC.

Categories