Convert timestamp to date in MySQL query
DATE_FORMAT(FROM_UNIXTIME(`user.registration`), ‘%e %b %Y’) AS ‘date_formatted’
DATE_FORMAT(FROM_UNIXTIME(`user.registration`), ‘%e %b %Y’) AS ‘date_formatted’
this is what i used: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@”yyyy-MM-dd”]; NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init]; [timeFormat setDateFormat:@”HH:mm:ss”]; NSDate *now = [[NSDate alloc] init]; NSString *theDate = [dateFormat stringFromDate:now]; NSString *theTime = [timeFormat stringFromDate:now]; NSLog(@”\n” “theDate: |%@| \n” “theTime: |%@| \n” , theDate, theTime); [dateFormat release]; [timeFormat release]; [now release];
This is documented behavior. From ?as.Date: format: A character string. If not specified, it will try ‘”%Y-%m-%d”‘ then ‘”%Y/%m/%d”‘ on the first non-‘NA’ element, and give an error if neither works. as.Date(“01 Jan 2000”) yields an error because the format isn’t one of the two listed above. as.Date(“01/01/2000”) yields an incorrect answer because the date … Read more
Within the scope of java.time-package, we can say: It is safer to use “u” instead of “y” because DateTimeFormatter will otherwise insist on having an era in combination with “y” (= year-of-era). So using “u” would avoid some possible unexpected exceptions in strict formatting/parsing. See also this SO-post. Another minor thing which is improved by … Read more
function timeSince(date) { var seconds = Math.floor((new Date() – date) / 1000); var interval = seconds / 31536000; if (interval > 1) { return Math.floor(interval) + ” years”; } interval = seconds / 2592000; if (interval > 1) { return Math.floor(interval) + ” months”; } interval = seconds / 86400; if (interval > 1) { … Read more
Altered piece of code I often use: Date.prototype.yyyymmdd = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [this.getFullYear(), (mm>9 ? ” : ‘0’) + mm, (dd>9 ? ” : ‘0’) + dd ].join(”); }; var date = new Date(); date.yyyymmdd();
Here’s a simple helper function that will format JS dates for you. function toIsoString(date) { var tzo = -date.getTimezoneOffset(), dif = tzo >= 0 ? ‘+’ : ‘-‘, pad = function(num) { return (num < 10 ? ‘0’ : ”) + num; }; return date.getFullYear() + ‘-‘ + pad(date.getMonth() + 1) + ‘-‘ + pad(date.getDate()) … Read more
If you don’t want to drag in libraries, it’s simple enough to do yourself using a Formatter, or related shortcut eg. given integer number of seconds s: String.format(“%d:%02d:%02d”, s / 3600, (s % 3600) / 60, (s % 60));
How do I get the current date in JavaScript?
How do I format a date in JavaScript?