Rails formatting date

Use Model.created_at.strftime(“%FT%T”) where, %F – The ISO 8601 date format (%Y-%m-%d) %T – 24-hour time (%H:%M:%S) Following are some of the frequently used useful list of Date and Time formats that you could specify in strftime method: Date (Year, Month, Day): %Y – Year with century (can be negative, 4 digits at least) -0001, 0000, … Read more

How do you globally set the date format in ASP.NET?

You can change the current thread culture in your Global.asax file, and override the date format for example: using System.Globalization; using System.Threading; //… protected void Application_BeginRequest(Object sender, EventArgs e) { CultureInfo newCulture = (CultureInfo) System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); newCulture.DateTimeFormat.ShortDatePattern = “dd-MMM-yyyy”; newCulture.DateTimeFormat.DateSeparator = “-“; Thread.CurrentThread.CurrentCulture = newCulture; }

How to format a Date in MM/dd/yyyy HH:mm:ss format in JavaScript? [duplicate]

Try something like this var d = new Date, dformat = [d.getMonth()+1, d.getDate(), d.getFullYear()].join(“https://stackoverflow.com/”)+’ ‘+ [d.getHours(), d.getMinutes(), d.getSeconds()].join(‘:’); If you want leading zero’s for values < 10, use this number extension Number.prototype.padLeft = function(base,chr){ var len = (String(base || 10).length – String(this).length)+1; return len > 0? new Array(len).join(chr || ‘0’)+this : this; } // usage … Read more

“Java DateFormat is not threadsafe” what does this leads to?

Let’s try it out. Here is a program in which multiple threads use a shared SimpleDateFormat. Program: public static void main(String[] args) throws Exception { final DateFormat format = new SimpleDateFormat(“yyyyMMdd”); Callable<Date> task = new Callable<Date>(){ public Date call() throws Exception { return format.parse(“20101022”); } }; //pool with 5 threads ExecutorService exec = Executors.newFixedThreadPool(5); List<Future<Date>> … Read more

Date formatting based on user locale on android

You can use the DateFormat class that formats a date according to the user locale. Example: String dateOfBirth = “26/02/1974”; SimpleDateFormat sdf = new SimpleDateFormat(“dd/MM/yyyy”); Date date = null; try { date = sdf.parse(dateOfBirth); } catch (ParseException e) { // handle exception here ! } java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); String s = dateFormat.format(date); You can … Read more

Parse date in MySQL

You may want to use the STR_TO_DATE() function. It’s the inverse of the DATE_FORMAT() function. STR_TO_DATE(str,format) This is the inverse of the DATE_FORMAT() function. It takes a string str and a format string format. STR_TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value … Read more

tech