小编Yve*_*eth的帖子

获取LocalDate的周数(Java 8)

我正在尝试使用以下格式获取完整LocalDate的周数:

dd.MM.yyy
Run Code Online (Sandbox Code Playgroud)

我还没有在Java 8 Date API中找到一个返回Week Number的函数,我试图创建一个算法,但它没有用.

java week-number java-8

28
推荐指数
2
解决办法
3万
查看次数

Java 8 DateTime检查句点是否包含特定日期

我想检查一下日期是否包含二月二十九日.

private static final MonthDay LEAP = MonthDay.of(Month.FEBRUARY, 29);
Run Code Online (Sandbox Code Playgroud)

我试过了:

if (LEAP.isAfter(beginDate) && LEAP.isBefore(maturity)) {

    }
Run Code Online (Sandbox Code Playgroud)

beginDatematurity是从类型LocalDate 这样的方法中.isAfter,并.isBefore不能使用.

beginDate是15.01.2012
maturity是二○一三年一月二十〇日

在此期间,2月29日存在

我终于找到了解决方案:

for (int i = beginDate.getYear(); i <= maturity.getYear(); i++) {
    final Year year = Year.of(i);
    if (year.isLeap()) {
        if (beginDate.compareTo(LEAP.atYear(i)) <= 0 || maturity.compareTo(LEAP.atYear(i)) >= 0) {
            minMaturity.plusDays(1);
        }
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

java datetime java-8 java-time

9
推荐指数
1
解决办法
3214
查看次数

ActionListener actionPerformed被调用两次

我有这个ActionListener:

logOutButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(getTextFieldContent());

        }
    });
Run Code Online (Sandbox Code Playgroud)

在这里我将按钮添加到面板:

c.fill = GridBagConstraints.RELATIVE;
c.anchor = GridBagConstraints.LAST_LINE_END;
c.gridwidth = 1;
this.add(logOutButton, c);
Run Code Online (Sandbox Code Playgroud)

如果JTextField的内容是test,则控制台输出为:

test
test
Run Code Online (Sandbox Code Playgroud)

所以我认为actionPerformed()方法被调用两次,但为什么呢?

编辑

孔码:

public GuiPanel(){
    super();
    this.setBorder(new EmptyBorder(10, 10, 10, 10) );
    //Layout:
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    this.setLayout(gridbag);
    setUpJButton();

    //label for textfield
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    gridbag.setConstraints(labelForName, c);
    this.add(labelForName);

    c.insets = new Insets(5, 0, 0, 0);//padding to top

    //textField
    c.fill = GridBagConstraints.HORIZONTAL;
    setUpTextField();
    c.gridwidth …
Run Code Online (Sandbox Code Playgroud)

java action onclicklistener

0
推荐指数
1
解决办法
3441
查看次数

PHP字符串切成碎片

我有一个登录表单,用户必须输入他的电子邮件地址.现在我想切断@和电子邮件域并将其保存为用户名.

例如:

$email = $_POST['email'];
//$email = muster.hans@gmail.com
Run Code Online (Sandbox Code Playgroud)

现在用户名应该是:

muser.hans
Run Code Online (Sandbox Code Playgroud)

php function output

-1
推荐指数
1
解决办法
66
查看次数

PHP多字符串比较

我想检查6个字符串是否不一样.我试过这个:

if($first != $second != $third != $four != $fifth != $sixth){}
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Parse error: syntax error, unexpected '!=' (T_IS_NOT_EQUAL)
Run Code Online (Sandbox Code Playgroud)

我不知道任何能做同样事情的功能.

php string compare

-2
推荐指数
1
解决办法
42
查看次数