Answers for "calculate age based on date in java"

16

git undo commit

# Uncommit the changes
git reset --soft HEAD~1

# Completely delete the changes
git reset --hard HEAD~1
Posted by: Guest on September-04-2020
2

how to revert back to previous commit in git

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.
Posted by: Guest on May-29-2020
8

git roll back to specific commit

//Git Rollback to a specific commit via Mac terminal

//Navigate to project and open git log
cd projectname
git log --oneline

//Locate and checkout the desired commit ID
git checkout abc1234 . 

//(Type q to quit the git log)

//Stage All changes, commit with comment, and push to remote
git add -A
git commit -m "Revert commit: abc1234"
git push
Posted by: Guest on January-10-2020
3

github restore previous commit

# syntax
git revert <commit>
# example
git revert 99a5c5905e12c74725bae64c61efce140662ce24
# where 99a5c59... is the commit (you can check it on github)
Posted by: Guest on September-12-2020
6

git go back to previous commit

git checkout 12feg3435 #commit ID
Posted by: Guest on January-13-2021
0

git how to roll back to a commit

//git use a new commit to replace an old commit,commit moves foward not backward
git revert <commit hash>
//Git goes back one spot on the log,undone this commit and go backward one commit:
git reset HEAD~1
//Git looks for and rolls back to a certain file:
git checkout commit-hash-here -- file/location/and/name
Posted by: Guest on July-16-2020
10

java age from date

LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1987, 09, 24);

Period period = Period.between(birthday, today);

//Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears());
Posted by: Guest on July-23-2020
0

how to calculate age on entry of dob in java

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
public class AgeCalculator
{
   private static Age calculateAge(Date birthDate)
   {
      int years = 0;
      int months = 0;
      int days = 0;
 
      //create calendar object for birth day
      Calendar birthDay = Calendar.getInstance();
      birthDay.setTimeInMillis(birthDate.getTime());
 
      //create calendar object for current day
      long currentTime = System.currentTimeMillis();
      Calendar now = Calendar.getInstance();
      now.setTimeInMillis(currentTime);
 
      //Get difference between years
      years = now.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
      int currMonth = now.get(Calendar.MONTH) + 1;
      int birthMonth = birthDay.get(Calendar.MONTH) + 1;
 
      //Get difference between months
      months = currMonth - birthMonth;
 
      //if month difference is in negative then reduce years by one 
      //and calculate the number of months.
      if (months < 0)
      {
         years--;
         months = 12 - birthMonth + currMonth;
         if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE))
            months--;
      } else if (months == 0 && now.get(Calendar.DATE) < birthDay.get(Calendar.DATE))
      {
         years--;
         months = 11;
      }
 
      //Calculate the days
      if (now.get(Calendar.DATE) > birthDay.get(Calendar.DATE))
         days = now.get(Calendar.DATE) - birthDay.get(Calendar.DATE);
      else if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE))
      {
         int today = now.get(Calendar.DAY_OF_MONTH);
         now.add(Calendar.MONTH, -1);
         days = now.getActualMaximum(Calendar.DAY_OF_MONTH) - birthDay.get(Calendar.DAY_OF_MONTH) + today;
      } 
      else
      {
         days = 0;
         if (months == 12)
         {
            years++;
            months = 0;
         }
      }
      //Create new Age object 
      return new Age(days, months, years);
   }
 
   public static void main(String[] args) throws ParseException
   {
      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
      Date birthDate = sdf.parse("29/11/1981");     
      Age age = calculateAge(birthDate);
      System.out.println(age);
   }
}
Posted by: Guest on July-29-2020

Code answers related to "calculate age based on date in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language