I need to get may as a current month, but I could not do. How can I achieve this?
let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components([.Day , .Month , .Year], fromDate: date) let year = components.year let month = components.month let day = components.day
I have done this but does not worked.
var date = new Date(); var month = date. getMonth(); The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.
To get the current month in typescript has the new Date(). getMonth() method which will return every time the current month index in number datatype. we have to just call new Date(). getMonth() and it will check the current date and return month index based on the date.
Answer: Use the toLocaleString() Method You can simply use the toLocaleString() method to get the month name from a date in JavaScript.
let now = Date() let dateFormatter = DateFormatter() dateFormatter.dateFormat = "LLLL" let nameOfMonth = dateFormatter.string(from: now)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With