I am trying to use a java.util.Date as input and then creating a query with it - so I need a java.sql.Date . I was surprised to find that it couldn't do the conversion implicitly or explicitly - but I don't even know how I would do this, as the Java API is still fairly new to me. tl;dr Use java.time classes instead of legacy java.util.Date & java.sql.Date with JDBC 4.2 or later.
我想用java.util.Date作为输入,然后用它创建一个查询 - 所以我需要一个java.sql.Date 。 我惊讶地发现它不能隐式或明确地进行转换 - 但我甚至不知道我会怎么做,因为Java API对我来说还是比较新的。 TL;博士 使用java.time类而不是使用JDBC 4.2或更高版本的传统java.util.Date & java.sql.Date 。 如果与尚未更新为java.time的代码交互操作,则转换为java.time。 用PreparedStatement查询示例。 myPreparedStatement
How to obtain the start time and end time of a day? code like this is not accurate: private Date getStartOfDay(Date date) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DATE); calendar.set(year, month, day, 0, 0, 0); return calendar.getTime(); } private Dat
如何获取一天的开始时间和结束时间? 这样的代码并不准确: private Date getStartOfDay(Date date) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DATE); calendar.set(year, month, day, 0, 0, 0); return calendar.getTime(); } private Date getEndOfDay(Date date) {
I've a String representing a date. String date_s = "2011-01-18 00:00:00.0"; I'd like to convert it to a Date and output it in YYYY-MM-DD format. 2011-01-18 How can I achieve this? Okay, based on the answers I retrieved below, here's something I've tried: String date_s = " 2011-01-18 00:00:00.0"; SimpleDateFormat dt = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss"); Date da
我有一个代表日期的String 。 String date_s = "2011-01-18 00:00:00.0"; 我想将其转换为Date并以YYYY-MM-DD格式输出。 2011-01-18 我怎样才能做到这一点? 好的,根据我在下面检索的答案,这里是我尝试过的东西: String date_s = " 2011-01-18 00:00:00.0"; SimpleDateFormat dt = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss"); Date date = dt.parse(date_s); SimpleDateFormat dt1 = new SimpleDateFormat("yyy
What is the best way to convert a string in the format 'January 2, 2010' to a date in Java? Ultimately, I want to break out the month, the day, and the year as integers so that I can use Date date = new Date(); date.setMonth().. date.setYear().. date.setDay().. date.setlong currentTime = date.getTime(); to convert the date into time. That's the hard way, and those java.util.Date
将'2010年1月2日'格式的字符串转换为Java日期的最佳方式是什么? 最终,我想把整月的月份,日期和年份分开,以便我可以使用 Date date = new Date(); date.setMonth().. date.setYear().. date.setDay().. date.setlong currentTime = date.getTime(); 将日期转换为时间。 这是困难的方式,自Java 1.1(1997)以来,这些java.util.Date setter方法已被弃用。 使用与输入字符串匹配的格式模式简单地使用SimpleDate
I need a Java program to get the current date without a timestamp : Date d = new Date(); gives me date and timestamp. But I need only the date, without a timestamp. I use this date to compare with another date object that does not have a timestamp. On printing System.out.println("Current Date : " + d) of d it should print May 11 2010 - 00:00:00 . A java.util.Date object is a kind of ti
我需要一个Java程序来获取没有时间戳的当前日期 : Date d = new Date(); 给我日期和时间戳。 但我只需要日期,没有时间戳。 我使用这个日期来比较没有时间戳的另一个日期对象。 打印时 System.out.println("Current Date : " + d) 它应该打印May 11 2010 - 00:00:00 。 一个java.util.Date对象是一种时间戳 - 它包含自1970年1月1日00:00:00 UTC以来的毫秒数。 所以你不能使用标准的Date对象来包含一天/一年/一年,
I am making an application for Android 3.1, which intercepts keyboard events and sends them to my server (Windows). Problem: My application (activity) is able to receive events for English characters, but when keyboard is other than English, keyup and keydown events are not reaching my application. Code snippet for launching keyboard: InputMethodManager mgr = (InputMethodManager) getSystemSe
我正在为Android 3.1制作一个应用程序,它拦截键盘事件并将它们发送到我的服务器(Windows)。 问题:我的应用程序(活动)能够接收英语字符的事件,但是当键盘不是英语时,键入和按键事件不能到达我的应用程序。 启动键盘的代码片段: InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); 重载以下函数: public boolean onKeyDown(int key
I programmed an easy Game in Android Studio. After game Over I want to switch to another Activity, but Intent doesn't work. Every time the app sends the error "unfortunalety stopped". I call the Intent in the onTouch Method when the Picture "donate" is pressed. I tried various combinations with context or with getApplicationContext() and so on. I surfed through variou
我在Android Studio中编写了一个简单的游戏。 游戏结束后,我想切换到另一个活动,但意图不起作用。 每当应用程序发送错误“不幸停止”。 当按下图片“捐赠”时,我在onTouch方法中调用Intent。 我尝试了使用上下文或getApplicationContext()等的各种组合。 我通过各种平台冲浪,但我没有解决问题! 谢谢你的帮助! 活动GamePlayScene public class GamePlayScene extends Activity implements Scene { @Override protec
I've got strange problem with my ViewFlipper. It's working perfectly, besides one particular situation. When I open my activity for the first time and tap first image instead of slide it, application shows error. But when I slide it it's works fine and shows next image. After this, when I go backwards to first image and tap it again, it's working good. My java code: import
我的ViewFlipper出现了奇怪的问题。 除了一个特定的情况外,它的工作完美无缺。 当我第一次打开我的活动并点击第一张图片而不是幻灯片时,应用程序显示错误。 但是当我滑动它时,它工作正常,并显示下一个图像。 在此之后,当我倒退到第一张图片并再次点击它时,它运行良好。 我的java代码: import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import
I'm trying to scale down a bitmap. In short, the image is originally from a ByteArray with a width of 4016. After I scale the image down with factory options, it still reports the image with a width of 4016. Here are two clips of my code: Bitmap myBitmap = null; @Override protected byte[] doInBackground(Object... params) { final BitmapFactory.Options options
我试图缩小一个位图。 简而言之,图像最初来自宽度为4016的ByteArray。在用工厂选项缩小图像后,它仍然报告宽度为4016的图像。 这里是我的代码的两个剪辑: Bitmap myBitmap = null; @Override protected byte[] doInBackground(Object... params) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; if (op
Which is the most efficient way to traverse a collection? List<Integer> a = new ArrayList<Integer>(); for (Integer integer : a) { integer.toString(); } or List<Integer> a = new ArrayList<Integer>(); for (Iterator iterator = a.iterator(); iterator.hasNext();) { Integer integer = (Integer) iterator.next(); integer.toString(); } Please note, that this is not an
哪种是遍历集合的最有效的方法? List<Integer> a = new ArrayList<Integer>(); for (Integer integer : a) { integer.toString(); } 要么 List<Integer> a = new ArrayList<Integer>(); for (Iterator iterator = a.iterator(); iterator.hasNext();) { Integer integer = (Integer) iterator.next(); integer.toString(); } 请注意,尽管最后一个问题的答案之一接近了,但这不是这个,