Questions tagged [relative-date]

48 questions
100
votes
17 answers

Javascript timestamp to relative time

I'm looking for a nice JS snippet to convert a timestamp (e.g. from Twitter API) to a nice user friendly relative time (e.g. 2 seconds ago, one week ago etc). Anyone care to share some of their favourite methods (preferably not using plugins)?
wilsonpage
  • 17,341
  • 23
  • 103
  • 147
42
votes
16 answers

How to convert NSDate in to relative format as "Today","Yesterday","a week ago","a month ago","a year ago"?

I want to convert nsdate in to relative format like "Today","Yesterday","a week ago","a month ago","a year ago","date as it is". I have written following method for it.. but some how its just printing as it is date.. can you please tell me what…
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
33
votes
10 answers

PHP: producing relative date/time from timestamps

I'm basically trying to convert a Unix timestamp (the time() function) to a relative date/time that's both compatible with past and future date. So outputs could be: 2 weeks ago 1 hour and 60 minutes ago 15 minutes and 54 seconds ago after 10…
KeyStroke
  • 1,455
  • 5
  • 19
  • 24
24
votes
4 answers

How to use Moment.js?

I'm unable to follow the Moment.js documentation, and need some help with setting it up. I've referenced the moment.min.js file properly on my webpage like so: Coming to the HTML part of my webpage, I have…
its_me
  • 10,998
  • 25
  • 82
  • 130
22
votes
4 answers

Swift iOS doesRelativeDateFormatting have different values besides "Today" and "Yesterday"?

I have a number of dates that I am trying to represent using a relative date such as "Today, Yesterday, 1 week ago, 1 month ago" etc... This is the Swift code I am using: let dateFormatter = NSDateFormatter() dateFormatter.dateStyle =…
Justin W.
  • 221
  • 1
  • 2
  • 3
18
votes
2 answers

Force Android DateUtils.getRelativeDateTimeString() to ignore the device locale?

I've found using the android.text.format.DateUtils relative APIs that return values like "yesterday" or "2 hours ago" very nice - but my app does not support every language Android does. So, I default to English, but for every language I don't…
Eric
  • 3,865
  • 4
  • 32
  • 44
14
votes
3 answers

default locale for getRelativeTimeSpanString

I override the locale of my app using: Locale locale = new Locale("ca"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, …
user1458180
  • 155
  • 2
  • 7
13
votes
3 answers

NSDateFormatter relative date formatting with custom format

So my intention is to put out dates that would look like the following: Today, August 28 Tomorrow, August 29 Friday, August 30 ...etc The issue is that it seems I can only get so close. When I setDoesRelativeDateFormatting:YES and setDateStyle to…
user1869469
  • 491
  • 4
  • 13
10
votes
4 answers

What's the best way to produce a relative date range (This week, This year, Last month, etc) from a DateTime?

I'm sure I'm not the first person to need to do this, so I'm looking for the best way. I've got a set of radio buttons with choices such as This Year Last Year This Month Last Month This Week Last Week and I need to produce the proper relative…
Redwood
  • 66,744
  • 41
  • 126
  • 187
7
votes
3 answers

How can I create relative/approximate dates in Perl?

I'd like to know if there are any libraries (preferably DateTime-esque) that can take a normal date time and create an appropriate relative human readable date. Essentially the exact opposite of the more common question: How can I parse relative…
Danny
  • 13,194
  • 4
  • 31
  • 36
4
votes
1 answer

Usage of 'next' in strtotime with multiple relative dates

After looking at the PHP.NET Relative Format Dates page, I'm still confused about the order of operations with multiple relative dates in strtotime when subtracting. I've noticed that the following returns 1/9/2015. strtotime('next friday -7 days',…
scottheckel
  • 9,106
  • 1
  • 35
  • 47
4
votes
2 answers

Can I parse relative times with JodaTime?

I'd love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn't seem to support English relative times and I don't know of any other parsing options in…
pr1001
  • 21,727
  • 17
  • 79
  • 125
3
votes
1 answer

How to get relative dates

how can I get relative dates in Objective-C? If I have "today", how do I find "yesterday", "last week", "last two weeks", "one month ago", "two months ago"?
Ali
  • 1,975
  • 5
  • 36
  • 55
3
votes
3 answers

How to convert dateutil.relativedelta object to datetime.timedelta object?

How can I convert a dateutil.relativedelta object to a datetime.timedelta object? e.g., # pip install python-dateutil from dateutil.relativedelta import relativedelta from datetime import timedelta rel_delta = relativedelta(months=-2) # How can I…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
3
votes
8 answers

Java: date & time relative to current (server) time

We're using MySQL to store some dates. I'm looking to show these as relative time periods in the user interface: 2 hours ago, 3 days ago etc. (Like Twitter does for the updates for example) Is there a well-known way to accomplish this, or should I…
Dan
  • 9,912
  • 18
  • 49
  • 70
1
2 3 4