我需要将一个数字舍入到最接近的5的倍数(向上或向下).例如,以下是数字列表及其旁边需要向上/向下舍入的数字.
12.5 10
62.1 60
68.3 70
74.5 75
80.7 80
Run Code Online (Sandbox Code Playgroud)
数字只会是积极的.
我有一个标准ISO 8601格式的字符串,其中包含从Web服务返回的日期/时间,如下所示:
String dtStart = "2010-10-15T09:27:37Z"
Run Code Online (Sandbox Code Playgroud)
如何将其转换为时间或日期等对象?我最初想要以不同的格式输出它,但是稍后需要用它做其他的东西(也就是说可能以不同的格式使用).
干杯
我花了很多时间在SBT和IntelliJ之间来回,从SBT获取文件,行号和错误,并在IntelliJ中导航到它.有没有办法自动化这个?即使它只是通过IntelliJ的编译器,我也希望能够导航到项目范围内的下一个错误.
我正在使用CheckStyle,FindBugs和PMD来验证我的Java代码.我已经修复了这些工具捕获的几乎所有错误.
我无法理解如何编写"包评论",这是checkstyle捕获的错误.我已经阅读了CheckStyle的文档,但我不明白.
有人可以帮助我在Java中编写包级别的注释吗?
您将如何重写下面的方法,该方法将返回下个月的第一天,org.joda.time包装在Joda-Time中?
public static Date firstDayOfNextMonth() {
Calendar nowCal = Calendar.getInstance();
int month = nowCal.get(Calendar.MONTH) + 1;
int year = nowCal.get(Calendar.YEAR);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, 1);
Date dueDate = new Date(cal.getTimeInMillis());
return dueDate;
}
Run Code Online (Sandbox Code Playgroud) 在Joda-Time,有没有办法获得一周的第一天(星期一)的日期.
例如,我想根据今天的当前日期21/01/11找出这个星期一星期一的日期
提前干杯.
编辑:我也希望找到一周结束的日期,即星期日的日期.干杯
我试图注册使用servletContainerInitializer一个servlet,但它似乎不工作,也许这是我的代码(好心审查),但是我到想知道的区别ServletContainerInitializer和ServletContextListener,因为使用时follwing代码运行正常ServletContextListener,而不是.
从servlet 3.0规范:
4.4
配置方法(动态添加servlet):
......或者从实施
onStartup方法ServletContainerInitializer......
的ServletContainerInitializer:
package com.marmoush.javaexamples.nullhaus.servlet;
import java.util.Set;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class MyInit implements ServletContainerInitializer {
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
System.out.println("hello");
ServletRegistration reg = ctx.addServlet("q31","com.marmoush.javaexamples.nullhaus.servlet.Q31");
reg.addMapping("/q31/*");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试自动注册的servlet:
package com.marmoush.javaexamples.nullhaus.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Q31 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) …Run Code Online (Sandbox Code Playgroud) 我想在下面替换第一次出现的String.
String test = "see Comments, this is for some test, help us"
Run Code Online (Sandbox Code Playgroud)
**如果测试包含如下输入,则不应替换
我想得到如下输出,
Output: this is for some test, help us
Run Code Online (Sandbox Code Playgroud)
提前致谢,
我在尝试:
NSDate *currentDateInLocal = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'"];
NSString *currentLocalDateAsStr = [dateFormatter stringFromDate:currentDateInLocal];
NSDateFormatter * dateFormatter2 = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter2 setTimeZone:timeZone];
[dateFormatter2 setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'"];
NSDate *currentDateInUTC = [dateFormatter2 dateFromString:currentLocalDateAsStr];
Run Code Online (Sandbox Code Playgroud)
但它仍然不代表当前的UTC时间,我该如何实现呢?
谢谢