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 6957573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:01:15+00:00 2026-05-27T15:01:15+00:00

I store current time in database each time application starts by user. Calendar c

  • 0

I store current time in database each time application starts by user.

Calendar c = Calendar.getInstance();
    String str = c.getTime().toString();
    Log.i("Current time", str);

In database side, I store current time as string (as you see in above code). Therefore, when I load it from database, I need to cast it to Date object. I saw some samples that all of them had used "DateFormat". But my format is exactly as same as Date format. So, I think there is no need to use "DateFormat". Am I right?

Is there anyway to directly cast this String to Date object? I want to compare this stored time with current time.


update

Thanks all. I used following code:

private boolean isPackageExpired(String date){
        boolean isExpired=false;
        Date expiredDate = stringToDate(date, "EEE MMM d HH:mm:ss zz yyyy");        
        if (new Date().after(expiredDate)) isExpired=true;
        
        return isExpired;
    }
    
    private Date stringToDate(String aDate,String aFormat) {
    
      if(aDate==null) return null;
      ParsePosition pos = new ParsePosition(0);
      SimpleDateFormat simpledateformat = new SimpleDateFormat(aFormat);
      Date stringDate = simpledateformat.parse(aDate, pos);
      return stringDate;            
    
   }
  • 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-27T15:01:16+00:00Added an answer on May 27, 2026 at 3:01 pm

    From String to Date

    String dtStart = "2010-10-15T09:27:37Z";  
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");  
    try {  
        Date date = format.parse(dtStart);  
        System.out.println(date);  
    } catch (ParseException e) {
        e.printStackTrace();  
    }
    

    From Date to String

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");  
    try {  
        Date date = new Date();  
        String dateTime = dateFormat.format(date);
        System.out.println("Current Date Time : " + dateTime); 
    } catch (ParseException e) {
        e.printStackTrace();  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store the current date & time which can be get by
My current app needs to store address information for a user. I'm currently debating
I am writing a Scheduling application, and each row in my Database Table is
I am designing a database that needs to store transaction time and valid time,
I'm using time() to store date in the database. I have some kind of
I want to store the current URL in a session variable to reference the
I need to be able to store the current height and width of a
HttpContext.Current.Items is a store that has a life span of the HTTP request. I'd
When is it appropriate to store data in HttpContext.Current.Items[...] vs storing data in ViewData[...]
One of the data structures in my current project requires that I store lists

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.