Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current month as String? [duplicate]

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.

like image 304
iron Avatar asked May 06 '17 13:05

iron


People also ask

How to get current month number in JavaScript?

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.

How do I get current month in TS?

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.

How to display month name in JavaScript?

Answer: Use the toLocaleString() Method You can simply use the toLocaleString() method to get the month name from a date in JavaScript.


1 Answers

let now = Date() let dateFormatter = DateFormatter() dateFormatter.dateFormat = "LLLL" let nameOfMonth = dateFormatter.string(from: now) 
like image 153
André Slotta Avatar answered Sep 22 '22 06:09

André Slotta