java出生年月框代码 java年月日代码

java编写一个简单的输入生日计算下一个生日时间的代码?

import java.util.Calendar;

成都创新互联是一家成都做网站、成都网站建设,提供网页设计,网站设计,网站制作,建网站,按需定制开发,网站开发公司,从2013年开始是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。

import java.util.Scanner;

import java.util.concurrent.TimeUnit;

/**

* Title: Test03.javabr

* Description:

*

* @author 王凯芳

* @date 2020年3月5日 下午6:03:04

* @version 1.0

*

* @request 编写一个方法能计算任何一个人今天离他最近下一次生日还有多少天,然后在主方法(main方法)中输入你的出生年月日,调用该方法的计算结果并输出信息“某某同学离自己最近下一次生日x天”。

*/

public class Test03 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("请输入你的姓名:");

String name = sc.nextLine();

System.out.println("请输入你的生日,格式为(2000/01/01):");

String line = sc.nextLine();

String[] strs = line.split("/");

if (strs.length == 3) {

int days = getDays(strs[0], strs[1], strs[2]);

if (days == 0) {

System.out.println(String.format("%s 同学,今天是你的生日,祝你生日快乐(#^.^#)", name, days));

} else {

System.out.println(String.format("%s 同学离自己最近下一次生日%d天。", name, days));

}

} else {

System.out.println("生日输入不正确!请按格式输入。");

}

sc.close();

}

/**

* 获取最近一次生日天数

*

* @param year

* @param month

* @param day

* @return

*/

public static int getDays(String year, String month, String day) {

Calendar now = Calendar.getInstance();

now.set(Calendar.HOUR_OF_DAY, 0);

now.set(Calendar.MINUTE, 0);

now.set(Calendar.SECOND, 0);

now.set(Calendar.MILLISECOND, 0);

int now_year = now.get(Calendar.YEAR);

Calendar birthday = Calendar.getInstance();

birthday.set(Calendar.YEAR, now_year);

birthday.set(Calendar.MONTH, Integer.parseInt(month) - 1);

birthday.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));

birthday.set(Calendar.HOUR_OF_DAY, 0);

birthday.set(Calendar.MINUTE, 0);

birthday.set(Calendar.SECOND, 0);

birthday.set(Calendar.MILLISECOND, 0);

long diff = now.getTimeInMillis() - birthday.getTimeInMillis();

if (diff == 0) {

return 0;

} else if (diff 0) {

long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);

return Math.abs((int) diffDays);

} else {

birthday.add(Calendar.YEAR, 1);

long diffMi = birthday.getTimeInMillis() - now.getTimeInMillis();

long diffDays = TimeUnit.DAYS.convert(diffMi, TimeUnit.MILLISECONDS);

return (int) diffDays;

}

}

}

用Java做 在输入文本框里输入出生年月,然后输出年龄,怎么做啊~!

用JLabel 或Label

我给你写了个开头

public class mainFrame extends JFrame{

JLabel jl = new JLabel("用户名称:");

JTextField jtf = new JTextField();

JPanel jp_group = new JPanel();

public loginFrame() {

try {

jbInit();common.mysession.dataTrf.getValue("main");

} catch (Exception exception) {

exception.printStackTrace();

}

}

帮忙写下代码java swing,个人信息实例

本人急忙做的:有什么不合要求的请再告诉我:

package show;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class Test extends JFrame implements ActionListener

{

GridBagLayout g=new GridBagLayout();

GridBagConstraints c=new GridBagConstraints();

Test(String str)

{

super(str);

setSize(300,500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(g);

//调用方法

addComponent();

submit.addActionListener(this);

setVisible(true);

setLocationRelativeTo(null);//设居中显示;

}

//在这个方法中将会添加所有的组件;

//使用的网格包布局;希望楼主能看懂;

public void addComponent()

{

//个人信息登记

noteInformation=new JLabel("个人信息登记:");

add(g,c,noteInformation,0,0,1,1);

//用户名

userName=new JLabel("用户名:");

add(g,c,userName,0,1,1,1);

//用户名输入框

textUserName=new JTextField(10);

add(g,c,textUserName,1,1,2,1);

//密码:

password=new JLabel("密码:");

add(g,c,password,0,2,1,1);

//密码输入框

textUserPassword=new JTextField(10);

add(g,c,textUserPassword,1,2,2,1);

//性别

sex=new JLabel("性别:");

add(g,c,sex,0,3,1,1);

//男 女单选框

sexMan=new JRadioButton("男");

add(g,c,sexMan,1,3,1,1);

sexGirl=new JRadioButton("女");

add(g,c,sexGirl,2,3,1,1);

ButtonGroup group=new ButtonGroup();

group.add(sexMan);

group.add(sexGirl);

//出生日期

birthday=new JLabel("出生日期:");

add(g,c,birthday,0,4,1,1);

//复选框及其内容

String[] YEARS=new String[65];

for(int i=1950,k=0;i=2014;i++,k++)

{

YEARS[k]=i+"年";

}

year=new JComboBox(YEARS);

add(g,c,year,1,4,1,1);

//复选框及内容

month=new JComboBox(MONTH);

add(g,c,month,2,4,1,1);

//submit按钮

submit=new JButton("submit");

c.insets=new Insets(7,0,4,0);

add(g,c,submit,1,5,1,1);

result=new JTextArea(15,20);

add(g,c,result,0,6,3,4);

}

/* public void ActionPerformed(ActionEvent e)

{

String s=textUserName.getText();

String t=textUserPassword.getText();

String k=sexMan.getText();

String v=sexGirl.getText();

String a=(String) year.getSelectedItem();

String b=(String)month.getSelectedItem();

String num="用户名:"+s+"\n"+"密码: "+t+"性别: "+(k==null?v:k)+"\n"+"出生日期:"+a+" "+b;

result.append(num);

}*/

public void add(GridBagLayout g,GridBagConstraints c,JComponent jc,int x ,int y,int gw,int gh)

{

c.gridx=x;

c.gridy=y;

c.anchor=GridBagConstraints.WEST;

c.gridwidth=gw;

c.gridheight=gh;

g.setConstraints(jc,c);

add(jc);

}

public static void main(String args[])

{

new Test("个人信息登记表");

}

JLabel noteInformation,userName,password;

JLabel sex,birthday;

JTextField textUserName,textUserPassword;

JRadioButton sexMan,sexGirl;

JComboBox year,month;

JButton submit;

JTextArea result;

final String[] MONTH={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};

@Override

public void actionPerformed(ActionEvent arg0)

{

String s=textUserName.getText();

String t=textUserPassword.getText();

String k=sexMan.getText();

String v=sexGirl.getText();

String a=(String) year.getSelectedItem();

String b=(String)month.getSelectedItem();

String num="用户名:"+s+"\n"+"密码: "+t+"\n 性别: "+(k==null?v:k)+"\n"+"出生日期:"+a+" "+b;

result.setText(num);

}

}

java中的年月日简单编程

将这段代码拷贝到UseBirthday类中和你的比较一下看看

public class UseBirthday {

public static void main(String[] args) {

Birthday a=new Birthday(2000,1,1);

a.GetBirthday();

a.Birthday(2008,5,12);

a.GetBirthday();

}

}

class Birthday {

private int Year, Month, Day;

Birthday(){

Year=2000;

Month=1;

Day=1;

}

Birthday(int y,int m,int d) {

Year = y;

Month = m;

Day = d;

}

public void Birthday(int y,int m,int d){

Year = y;

Month = m;

Day = d;

}

int Gety() {

return Year;

}

int Getm() {

return Month;

}

int Getd() {

return Day;

}

void GetBirthday() {

System.out.println(Gety() + "年" + Getm() + "月" + Getd() + "日");

}

}

java源代码是给你一个身份证号,通过面板身份证号的输入,显示出该身份证主人的出生年月,省份,性别等资料

我当初用struts1和hibernate做了个简单的!主要的逻辑代码在下面!数据库里号码对应的城市在网上可以查的到

package dao;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.List;

import org.hibernate.Criteria;

import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.cfg.Configuration;

import org.hibernate.criterion.Expression;

import entity.Shenfenzhen;

public class IdDao {

private static Configuration configuration = new Configuration().configure() ;

private static SessionFactory sessionFactory =configuration.buildSessionFactory();

private static Session session = null;

public Info query(String s){

Info info = null;

StringBuffer stringBuffer = new StringBuffer(s);

if(s.length()==18){

String end = stringBuffer.substring(17);

//System.out.println(end);

if(!end.matches("\\d||x")){

return null;

}

}

else if(s.length()==15){

stringBuffer.insert(6, "19");

stringBuffer.append("3");

}

int i = Integer.parseInt(stringBuffer.substring(0, 6));

//System.out.println(i);

session = sessionFactory.openSession();

Criteria criteria = session.createCriteria(Shenfenzhen.class);

criteria.add(Expression.eq("num", i));

ListShenfenzhen list = criteria.list();

String address = null;

try {

address = list.get(0).getAddress();

}catch (Exception e) {

return null;

}

i = Integer.parseInt(stringBuffer.substring(16,17));

String sex = null;

if(i%2==0){

sex = "女";

}else{

sex = "男";

}

//System.out.println(i);

stringBuffer = new StringBuffer(stringBuffer.substring(6, 14));

// stringBuffer.insert(4, "-");

// stringBuffer.insert(7, "-");

//System.out.println(stringBuffer);

String ss = stringBuffer.toString();

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

String brithday="";

int year=0;

int month =0;

int day =0;

try {

Date date = dateFormat.parse(ss);

//System.out.println(date);

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

year = calendar.get(Calendar.YEAR);

month = calendar.get(Calendar.MONTH)+1;

day = calendar.get(Calendar.DAY_OF_MONTH);

brithday = (String)(year + "年" + month + "月" + day + "日");

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

info = new Info(address, brithday, sex);

Calendar c = Calendar.getInstance();

int nowYear = c.get(Calendar.YEAR);

int nowMonth = c.get(Calendar.MONTH);

int nowDay = c.get(Calendar.DAY_OF_MONTH);

if(nowYearyear){

info = null;

}else if(nowYear ==year nowMonthmonth ){

info = null;

}else if(nowYear == year nowMonth==month nowDayday){

info = null;

}

closeSession(session);

return info;

}

// public static void main(String[] args){

// IdDao dao = new IdDao();

// dao.query("342522998711224513");

// System.out.println("x".matches("\\d||x"));

// }

private void closeSession(Session session){

if(session !=null){

session.close();

}

}

}

JAVA写一个程序,要求输入身份证号获取所在地区代码也就是前六位,和出生年月。

import java.util.*;

public class Yugi{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

System.out.println("输入身份证号码: ");

String code = scan.nextLine().trim();

scan.close();

String reg = "^(.{6})(.{4})(.{2}).*$";

String a = code.replaceAll(reg, "$1");

String y = code.replaceAll(reg, "$2");

String m = code.replaceAll(reg, "$3");

System.out.println("所在地区代码:" + a);

System.out.println("出生年月: " + y + ", " + m);

}

}


新闻名称:java出生年月框代码 java年月日代码
文章分享:http://azwzsj.com/article/docjpjp.html