Topic: 如何将某个日期转化成对应的星期几?? |
Print this page |
1.如何将某个日期转化成对应的星期几?? | Copy to clipboard |
Posted by: fighttodeath Posted on: 2006-07-06 22:06 请各位高手帮忙说说算法。。 谢谢。。。 |
2.Re:如何将某个日期转化成对应的星期几?? [Re: fighttodeath] | Copy to clipboard |
Posted by: why Posted on: 2006-07-06 22:33 int yourDayOfWeek = yourDate.get(Calendar.DAY_OF_WEEK); Sun = 1 Mon = 2 ... http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#get(int) http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#DAY_OF_WEEK http://java.sun.com/j2se/1.4.2/docs/api/constant-values.html#java.util.Calendar.SUNDAY |
3.Re:如何将某个日期转化成对应的星期几?? [Re: fighttodeath] | Copy to clipboard |
Posted by: zcjl Posted on: 2006-07-06 22:33 请查看java.util.Calendar的JavaDoc |
4.Re:如何将某个日期转化成对应的星期几?? [Re: fighttodeath] | Copy to clipboard |
Posted by: myohmy Posted on: 2006-07-06 22:43 我以前写的哈 import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.String; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JFrame; public class calendar extends JFrame { private JButton okJButton; private JLabel weekJLabel,yearJLabel,monJLabel,dayJLabel; private JTextField weekJTextField,yearJTextField,monJTextField,dayJTextField; public calendar(){ createUserInterface(); } // create and position GUI components private void createUserInterface() { Container contentPane = getContentPane(); contentPane.setLayout( null ); // set up scanJButton yearJLabel= new JLabel(); yearJLabel.setBounds( 10, 20, 80, 20 ); yearJLabel.setText( "年"); contentPane.add(yearJLabel); monJLabel= new JLabel(); monJLabel.setBounds( 100, 20, 80, 20 ); monJLabel.setText( "月"); contentPane.add( monJLabel); dayJLabel= new JLabel(); dayJLabel.setBounds( 200, 20,80, 20 ); dayJLabel.setText( "日"); contentPane.add( dayJLabel); yearJTextField= new JTextField(); yearJTextField.setBounds( 10, 80, 80, 20 ); yearJTextField.setText( ""); contentPane.add(yearJTextField); monJTextField= new JTextField(); monJTextField.setBounds( 100, 80, 80, 20 ); monJTextField.setText( ""); contentPane.add(monJTextField); dayJTextField= new JTextField(); dayJTextField.setBounds( 200, 80, 80, 20 ); dayJTextField.setText( ""); contentPane.add(dayJTextField); okJButton = new JButton(); okJButton.setBounds( 10, 150, 65, 42 ); okJButton.setText( "ok" ); okJButton.setBackground( Color.ORANGE ); contentPane.add( okJButton); okJButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ okJButtonActionPerformed(event); } } ); weekJLabel= new JLabel(); weekJLabel.setBounds( 100, 220, 80, 20 ); weekJLabel.setText( "星期"); contentPane.add(weekJLabel); weekJTextField= new JTextField(); weekJTextField.setBounds( 170, 220, 80, 20 ); weekJTextField.setText( ""); contentPane.add(weekJTextField); setTitle( "canlender" ); // set title bar text setSize( 305, 320 ); // set window size setVisible( true ); // display window } // end method createUserInterface private void okJButtonActionPerformed( ActionEvent event ) { int year=Integer.parseInt(yearJTextField.getText()); int mon=Integer.parseInt(monJTextField.getText()); int day=Integer.parseInt(dayJTextField.getText()); Calendar cal = new GregorianCalendar(year,mon-1,day); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if ((dayOfWeek-1)==0) weekJTextField.setText("日"); else weekJTextField.setText(String.valueOf(dayOfWeek-1)); } public static void main( String[] args ) { calendar application = new calendar(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } // end method main } |
5.Re:如何将某个日期转化成对应的星期几?? [Re: fighttodeath] | Copy to clipboard |
Posted by: fighttodeath Posted on: 2006-07-07 09:25 非常感谢各位。。 谢谢。。 |
6.Re:如何将某个日期转化成对应的星期几?? [Re: fighttodeath] | Copy to clipboard |
Posted by: fanchen1111 Posted on: 2006-09-21 08:52 上面那个程序有一点小问题,对于月份和日期没有限制大小,月份中输入1000也能计算出结果,需要改进一下 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |