Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:27:47+00:00 2026-05-27T23:27:47+00:00

I am displaying Facebook posts in my Android application using the Facebook SDK. I

  • 0

I am displaying Facebook posts in my Android application using the Facebook SDK. I have the created_time for each post in the format:

2012-01-04T12:28:52+0000

I was able to parse this into a Java Date object like so:

public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss+SSSS";
public static Date parseDate(String str) {
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

    try {
        Date date = sdf.parse(str);
    } catch(ParseException e) {
        Log.w(TAG, "Unable to parse date string \"" + str + "\"");
    }
    return date;
  }

Then, I am attempting to display a message describing the time that has elapsed since the post was created using this method:

public static String timeAgoInWords(Date from) {
    Date now = new Date();
    long difference = now.getTime() - from.getTime();
    long distanceInMin = difference / 60000;

    if ( 0 <= distanceInMin && distanceInMin <= 1 ) {
        return "Less than 1 minute ago";
    } else if ( 1 <= distanceInMin && distanceInMin <= 45 ) {
        return distanceInMin + " minutes ago";
    } else if ( 45 <= distanceInMin && distanceInMin <= 89 ) {
        return "About 1 hour";
    } else if ( 90 <= distanceInMin && distanceInMin <= 1439 ) {
        return "About " + (distanceInMin / 60) + " hours ago";
    } else if ( 1440 <= distanceInMin && distanceInMin <= 2529 ) {
        return "1 day";
    } else if ( 2530 <= distanceInMin && distanceInMin <= 43199 ) {
        return (distanceInMin / 1440) + "days ago";
    } else if ( 43200 <= distanceInMin && distanceInMin <= 86399 ) {
        return "About 1 month ago";
    } else if ( 86400 <= distanceInMin && distanceInMin <= 525599 ) {
        return "About " + (distanceInMin / 43200) + " months ago";
    } else {
        long distanceInYears = distanceInMin / 525600;
        return "About " + distanceInYears + " years ago";
    }
}

The problem is that the create_time of the post is 6 hours ahead of my time (EST). So the timeAgoInWords method doesn’t work correctly. Does Facebook always record the creation time of posts in UTC/GMT +1 hour?

What can I do to convert the creation time so that timeAgoInWords will work correctly for the current user’s timezone, no matter where they are?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:27:48+00:00Added an answer on May 27, 2026 at 11:27 pm

    This is the code I use to convert a UTC time string to a localized time string. Note the key for conversion is to use the TimeZone methods getRawOffset(), inDaylightTime(...) and getDSTSavings().

    Note my date format is slightly different to what you are using so you’ll need to change it.

    public String GetLocalDateStringFromUTCString(String utcLongDateTime) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String localDateString = null;
    
        long when = 0;
        try {
            when = dateFormat.parse(utcLongDateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        localDateString = dateFormat.format(new Date(when + TimeZone.getDefault().getRawOffset() + (TimeZone.getDefault().inDaylightTime(new Date()) ? TimeZone.getDefault().getDSTSavings() : 0)));
    
        return localDateString;
    }
    

    Obviously you want a Date object so you just need to change this line…

    localDateString = dateFormat.format(new Date(when + TimeZone.getDefault().getRawOffset() + (TimeZone.getDefault().inDaylightTime(new Date()) ? TimeZone.getDefault().getDSTSavings() : 0)));
    

    …to…

    Date localDate = new Date(when + TimeZone.getDefault().getRawOffset() + (TimeZone.getDefault().inDaylightTime(new Date()) ? TimeZone.getDefault().getDSTSavings() : 0));
    

    …then you just need to change the return type of the method and return localDate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Facebook application I am displaying a message window using FB.ui { method:
I have created a simple Facebook application in PHP, that greets user by there
I have a facebook app that is displaying random quotes - it is written
I have added multiple labels in My Tableview cell. I am displaying facebook message
On https://www.eventhello.com/overridden_routes/not_mobile , I have an iFrame displaying the mobile version of our application.
I'm using facebook connect to let users login my application easy. It works well,
I'm displaying a set of images as an overlay using Google Maps. Displaying these
I have some text displaying in a larger font size than what it is
I'm trying to use the PyroCMS Contact form in a facebook tab. When displaying
I'm trying to integrate a Facebook send button into my site using Facebook app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.