ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

How to insert date in ActiveRecord !

Open deshario opened this issue 8 years ago • 1 comments

@Column(name = "timestamp", index = true) private Date timestamp;

Or

@Column(name = "created_at") private String created_at;

Should i use String or Date .... Can i have example of how to insert date into sqlite properly ! Thankyou

deshario avatar Jul 02 '17 05:07 deshario

ActiveAndroid supports serializing Date fields automatically. It is stored internally as a timestamp (INTEGER) in milliseconds.

@Column(name = "timestamp", index = true)
private Date timestamp; 

Create a Util method to convert String to Date, if you want:

public Date getDateFromString(String selectedDate) throws ParseException{
    DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
    Date date = format.parse(selectedDate);
    return date;
}

ps. ActiveAndroid has a pretty strong community on Stack Overflow, so you're welcome to ask your questions there. Actually this answer is copied from the Stack Overflow.

naXa777 avatar Jul 02 '17 08:07 naXa777