给定一个特定DateTime值,我如何显示相对时间,如:
在Ruby on Rails中,有一个功能允许你采取任何日期并打印出"很久以前"的样子.
例如:
8 minutes ago
8 hours ago
8 days ago
8 months ago
8 years ago
Run Code Online (Sandbox Code Playgroud)
在Java中有一种简单的方法吗?
如何查找自日期时间戳以来经过的时间2010-04-28 17:25:43,最终输出文本应该像xx Minutes Ago/xx Days Ago
我不太擅长处理datetime。我使用momentjs作为离子应用程序来操纵时间,但我想实现一些我无法实现的目标。
我使用了一个管道,我想根据过去了多少天、几周、几个月还是几年来显示。使用相对时间会帮助我,就像momentjsfromNow()的方法和方法calendar()一样。但就我而言,我会有多个.conditions
这是我的管道的示例代码
transform(value: Date | moment.Moment, dateFormat: string): any {
if (moment(value) < moment(value).subtract(7, 'days')) {
return moment(value).format('llll') // Use this format if weeks, months or years has passed
} else if (moment(value) < moment(value).subtract(1, 'days')) {
return moment(value).calendar(); // Use calendar time if 1 day has passed
} else {
return moment(value).fromNow(); // Use relative time if within 24 hours
}
}
Run Code Online (Sandbox Code Playgroud)
如果经过几秒、几分钟或几小时直到 24 …
javascript datetime datetime-format momentjs relative-time-span
我正在使用Groovy.我已经解析了一个文本文件,其行包含信息,包括日期.我现在只有日期,例如:
08:13:16,121
09:32:42,102
10:43:47,153
Run Code Online (Sandbox Code Playgroud)
我想比较这些值之间的增量; 我怎样才能做到这一点?即,我想从第二个中减去第一个,并将该值与第三个和第二个之间的差值进行比较.我会保存最大的值.
我已经完成了这段代码
+ (NSString *)relativeDateStringForDate:(NSString *)date
{
NSString *temp;
NSString* format = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
// Set up an NSDateFormatter for UTC time zone
NSDateFormatter* formatterUtc = [[NSDateFormatter alloc] init];
[formatterUtc setDateFormat:format];
[formatterUtc setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Cast the input string to NSDate
NSDate* utcDate = [formatterUtc dateFromString:date];
// Set up an NSDateFormatter for the device's local time zone
NSDateFormatter* formatterLocal = [[NSDateFormatter alloc] init];
[formatterLocal setDateFormat:format];
[formatterLocal setTimeZone:[NSTimeZone localTimeZone]];
// Create local NSDate with time zone difference
NSDate* localDate = [formatterUtc dateFromString:[formatterLocal stringFromDate:utcDate]]; …Run Code Online (Sandbox Code Playgroud)