I use the jQuery UI Month Picker Plugin to add a month picker in my app.
I don't find the way to get the value of the selected month in Javascript ?
I see in documentation you could get the month as a number! simply create a array with 12 months and use the method GetSelectedMonth() and use that number to get the relevant month from the array.
var arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
arr[GetSelectedMonth()-1] //-1 is used since array starts from 0
I am sharing the link you could get the month as a number! simply create a array with 12 months and use that number to get the relevant month from the array.
"http://jsfiddle.net/tmnasim/JLydp/"
Related
I am building a calendar component in React without using any library but Day.js.
I need to detect the first weekday of the month in order to leave a gap as shown in the picture. Otherwise the first day of every month has to be Sunday. How can I detect the first weekday of the given date?
Day.js has built in function to achieve this
dayjs().startOf("month").day()
This method returns current month's first week day as number.
0 = Sunday,
6 = Saturday
I have one problem. Can you tell me how to check does it day in the current week?
I am working on some service for a weather forecast. I have a current day but must check does it in the current week. Only what I know is that I must use 'isSame' function from Moment JS.
This is my line of code.
if(this.conversation.payload.grain==="week" && moment().startOf('week').isSame(this.conversation.payload.forecastTime))
"forecastTime" is a current day. However, the condition is not good and does not enter the if loop.
Thank you!
This is assuming your forecastedDate is an actual javascript date or a moment object.
The isSame function also takes in a granularity parameter.
Just add the 'week' parameter to the isSame method like so:
if(this.conversation.payload.grain==="week" &&
moment().startOf("week").isSame(this.conversation.payload.forecastTime, "week"))
To get the day of the week is easily done with the momentjs library.
This will give you a day of the week based on the locale:
var dayOfWeek = moment(this.conversation.payload.forecastTime).weekday()
For example, if the locale uses Monday as the first day of the week then 0 = Monday and 6 = Sunday. Please keep in mind that the value you recieve will change based on the current locale.
If you don't want the value to change based on locale but always want to receive a Monday-Sunday value use isoWeekday():
var dayOfWeek = moment(this.conversation.payload.forecastTime).isoWeekday()
This will give you an integer 1-7. 1 = Monday, 7 = Sunday.
So, for example, if the above code returned 4, you would know that it was Thursday.
For more details on the weekday(), isoWeekday, and day() functions, check out the momentjs docs.
I want to add number of days like 2,3,4 to current date of another data in laravel
If you mean add add number of days to current today date you can use
carbon
$num=4;
\Carbon\Carbon::now()->addDays($num);
I'm currently just practising JavaScript and I'm trying to create a programme that calculates how many days there are until your next birthday.
I have seen on this site that there is a daysBetween function that I can use to tell the time difference between two dates (I just need to turn these dates into the millisecond value since the 1st Jan 1970).
The problem is that, although one of those dates is the current date (which is easy to convert into its millisecond value), the second is derived from answers the user inputs as a string into a prompt command (there are three different boxes that ask for the year, month and date of their birth). Is there a way I can convert these input strings into a date format that I can then use to find the days between today's date and their next birthday?
Thanks and sorry if this is a stupid question!
Remember in JS that months are indexed from 0, so January === 0.
var date = new Date('2017','5','25'); would be today, assume you have something like:
var userDd = '25';
var userMm = '6'; // User doesn't know the months are indexed at 0.
var userYy = '2017';
var date = new Date(userYy, userMm - 1, userYy);
date.getTime(); // returns the milliseconds value.
i would like to create a url based on the year and the week number in order to redirect to a document which the name changes every week :
the document is stored at this place : server.com/kw38_2013.pdf (which kw38 mean week 38)
Does someone know a javascript for that ?
Regards
Emmanuel
It will be very easy to get year from a given date object in javascript. See Date Object Reference.
Whereas, Getting the week number from the given date will be tricky. Here is a similar question to get the week number from given date. See Get week of year in JavaScript.
Hope it helps.
See here to get the week number.
You get the year by creating a Date object : new Date().getFullYear()