Skip to content

Instantly share code, notes, and snippets.

@sidishere
Created December 24, 2019 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidishere/5737b0c4820c3b99218bc332cea612ee to your computer and use it in GitHub Desktop.
Save sidishere/5737b0c4820c3b99218bc332cea612ee to your computer and use it in GitHub Desktop.
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import java.util.Calendar;
public class DetailsActivity extends AppCompatActivity {
    String[] strDays = {
            "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday”s};
    Calendar myDOB=Calendar.getInstance();
    Calendar now=Calendar.getInstance();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        TextView textview= findViewById(R.id.day);
        Intent intent = getIntent();
        String dob=intent.getStringExtra("dateOfBirth");
        int year=Integer.parseInt(dob.substring(6,10));
        int month=Integer.parseInt(dob.substring(3,5))-1;
        int day=Integer.parseInt(dob.substring(0,2));
        int curYear=now.get(Calendar.YEAR);
        int curMonth=now.get(Calendar.MONTH);
        int curday=now.get(Calendar.DATE);
        myDOB.set(year,month,day);
        now.set(curYear,curMonth,curday);
        Log.i("A","Cur year"+curYear+" "+curMonth+" "+curday);
        if(myDOB.compareTo(now)<=0)
            textview.setText("You were born on "+strDays[myDOB.get(Calendar.DAY_OF_WEEK)-1]);
        else
textview.setText("No wait you cant be here now and be born in the future.");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment