Java中Java.util.Date无法导入的问题

昨天我遇到了这个纠结的问题,搞死了快被它,用的是jdk1.80,暑假里面才装上的,准备自学的勒,结果被卡在这时间格式化上老半天,我一开始写的程序是:

//import java.text.DateFormat;
import java.util.Date;
public class GetDate {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date now =new Date();

String hour = String.format("%tH",date);

      String minute = String.format("%tM",date);

String second = String.format("%tS",date);

System.out.println("现在是:"+hour+"时"+minute+"分"+second+"秒");//输出的信息 
// DateFormat d1 = DateFormat.getDateInstance();
// String str1 = d1.format(now);
// System.out.println("用Date"+ now);
// System.out.println("用DateFormat.getDateInstance()"+str1);
}
}

结果搞死了也没将format搞好,总是显示format错误,问了好多人都没有回答上来的,然后我又换了一个方法,改为引用java.util.text类,用DateFormat来实现时间的格式化,结果,这次是java.util.text无法引用,伤心得要死,本以为是JRE没设置对,结果检查半天啥事没有,最后实在没办法了,随便改了几行代码,又好了,不知咋回事勒,Java太坑爹了,不同版本经常会修改规则,所以在这给各位初学者一个建议,刚开始学的时候,自学的教材一定要准备对,其所用的jdk版本和比电脑上的jdk版本最好相同,否则相差太大的话,经过几个版本的演变之后可能很多外部引用类会有所修改,学习的过程中会遇到各种问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package data3; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLDataException; import java.sql.SQLException; import java.text.ParseException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Scanner; import data3.test.classselect; public class main { private static List<tele> telelist=new ArrayList<tele>(); public static void main(String[] args) throws ClassNotFoundException, SQLException { Scanner scanner = new Scanner(System.in); int choice; while (true) { displayMenu(); choice = scanner.nextInt(); scanner.nextLine(); // 清除输入缓冲区的换行符 switch (choice) { case 1: showUserList(); break; case 2: update(); break; case 3: Insert(); break; case 4: delete(); break; case 0: System.out.println("感谢使用!"); return; default: System.out.println("无效的选项,请重新输入。"); } } } private static void displayMenu() { System.out.println("------------------手机营销充值心----------------"); System.out.print("1. 查看手机用户列表"); System.out.print(" 2. 充值"); System.out.print(" 3. 新用户注册"); System.out.print(" 4. 老用户注销"); System.out.println(" 0. 退出"); System.out.print("请选择操作:"); } private static List<tele> showUserList() throws SQLException { Connection conn=null; PreparedStatement pst =null; ResultSet rs =null; try { conn = classselect.getConnection(); String sql = "select * from phone"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); List<tele;;这是一串代码,请帮我完善
06-13
telelist = new ArrayList<tele>(); // 创建手机用户列表 while (rs.next()) { // 遍历结果集并将每个用户添加到列表 int id = rs.getInt(1); String name = rs.getString(2); String gender = rs.getString(3); String phone = rs.getString(4); int balance = rs.getInt(5); telelist.add(new tele(id, name, gender, phone, balance)); } System.out.println("手机用户列表:"); System.out.println("编号\t姓名\t性别\t手机号码\t余额"); for (tele t : telelist) { // 遍历用户列表并输出用户信息 System.out.println(t.getId() + "\t" + t.getName() + "\t" + t.getGender() + "\t" + t.getPhone() + "\t" + t.getBalance()); } return telelist; } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); pst.close(); conn.close(); } return null; } private static void update() throws SQLException { Scanner scanner = new Scanner(System.in); System.out.print("请输入要充值的手机号码:"); String phone = scanner.next(); System.out.print("请输入充值金额:"); int amount = scanner.nextInt(); Connection conn=null; PreparedStatement pst =null; ResultSet rs =null; try { conn = classselect.getConnection(); String sql = "update phone set balance=balance+? where phone=?"; pst = conn.prepareStatement(sql); pst.setInt(1, amount); pst.setString(2, phone); int rows = pst.executeUpdate(); if (rows > 0) { System.out.println("充值成功!"); } else { System.out.println("充值失败,请检查手机号码是否正确。"); } } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); pst.close(); conn.close(); } } private static void Insert() throws SQLException { Scanner scanner = new Scanner(System.in); System.out.print("请输入姓名:"); String name = scanner.next(); System.out.print("请输入性别:"); String gender = scanner.next(); System.out.print("请输入手机号码:"); String phone = scanner.next(); System.out.print("请输入初始余额:"); int balance = scanner.nextInt(); Connection conn=null; PreparedStatement pst =null; ResultSet rs =null; try { conn = classselect.getConnection(); String sql = "insert into phone(name,gender,phone,balance) values(?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, name); pst.setString(2, gender); pst.setString(3, phone); pst.setInt(4, balance); int rows = pst.executeUpdate(); if (rows > 0) { System.out.println("注册成功!"); } else { System.out.println("注册失败,请检查手机号码是否已注册。"); } } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); pst.close(); conn.close(); } } private static void delete() throws SQLException { Scanner scanner = new Scanner(System.in); System.out.print("请输入要注销的手机号码:"); String phone = scanner.next(); Connection conn=null; PreparedStatement pst =null; ResultSet rs =null; try { conn = classselect.getConnection(); String sql = "delete from phone where phone=?"; pst = conn.prepareStatement(sql); pst.setString(1, phone); int rows = pst.executeUpdate(); if (rows > 0) { System.out.println("注销成功!"); } else { System.out.println("注销失败,请检查手机号码是否正确。"); } } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); pst.close(); conn.close(); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值