Get current date in DD-Mon-YYY format in JavaScript/Jquery

There is no native format in javascript for DD-Mon-YYYY. You will have to put it all together manually. The answer is inspired from : How do I format a date in JavaScript? // Attaching a new function toShortFormat() to any instance of Date() class Date.prototype.toShortFormat = function() { const monthNames = [“Jan”, “Feb”, “Mar”, “Apr”, …

Read more

Calculating the difference between two dates in Swift

I ended up creating a custom operator for Date: extension Date { static func – (lhs: Date, rhs: Date) -> TimeInterval { return lhs.timeIntervalSinceReferenceDate – rhs.timeIntervalSinceReferenceDate } } With this operator I can now compute the difference between two dates on a more abstract level without caring about timeIntervalSinceReferenceDate or what exactly the reference date …

Read more

Easiest way to convert month name to month number in JS ? (Jan = 01)

Just for fun I did this: function getMonthFromString(mon){ return new Date(Date.parse(mon +” 1, 2012″)).getMonth()+1 } Bonus: it also supports full month names 😀 Or the new improved version that simply returns -1 – change it to throw the exception if you want (instead of returning -1): function getMonthFromString(mon){ var d = Date.parse(mon + “1, 2012”); …

Read more

Convert java.time.Instant to java.sql.Timestamp without Zone offset

I changed my computer’s time zone to Europe/Bucharest for an experiment. This is UTC + 2 hours like your time zone. Now when I copy your code I get a result similar to yours: Instant now = Instant.now(); System.out.println(now); // prints 2017-03-14T06:16:32.621Z Timestamp current = Timestamp.from(now); System.out.println(current); // 2017-03-14 08:16:32.621 Output is given in comments. …

Read more

A good date converter for Jalali Calendar in Java? [closed]

For better localization and language support, it is often convenient to use the ICU (International Components for Unicode) library from IBM. The APIs are similar to the standard Java APIs, but add additional support for localization and internationalization (e.g. time and calendar issues, sorting, formatting rules and a regex implementation with proper Unicode support). To …

Read more