小编fen*_*nec的帖子

如何解析日期?

我试图解析这个日期,SimpleDateFormat它不起作用:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Formaterclass {
    public static void main(String[] args) throws ParseException{
        String strDate = "Thu Jun 18 20:56:02 EDT 2009";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date dateStr = formatter.parse(strDate);
        String formattedDate = formatter.format(dateStr);
        System.out.println("yyyy-MM-dd date is ==>"+formattedDate);
        Date date1 = formatter.parse(formattedDate);

        formatter = new SimpleDateFormat("dd-MMM-yyyy");
        formattedDate = formatter.format(date1);
        System.out.println("dd-MMM-yyyy date is ==>"+formattedDate);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我用strDate =尝试这个代码"2008-10-14",我有一个肯定的答案.有什么问题?我该如何解析这种格式?

PS.我从a获得了这个日期,jDatePicker没有关于如何修改用户选择日期时获得的日期格式的说明.

java date simpledateformat

177
推荐指数
4
解决办法
38万
查看次数

我如何清除所有铁路会话?

这是我的代码:

if session[:firsttimestart].nil? 
else
  @firsttime = false
end

if @firsttime == true
  initglobals()
end
session[:firsttimestart]=false
Run Code Online (Sandbox Code Playgroud)

问题是当我关闭服务器并返回应用程序时,会话[:firsttimestart]仍为false.它以某种方式将此变量存储在我的系统中而没有到期日期,因此不会调用iniglobals().我试图使用rake tmp:clear但它没有用.每次重新启动服务器时,如何清除系统中正在使用的所有会话?

session ruby-on-rails

29
推荐指数
4
解决办法
3万
查看次数

用json跟踪日期

我正在实现一个Facebook应用程序并使用AJAX/JSON.

但是,返回的JSON结构具有此格式2010-05-30T06:14:00Z.

我打电话给Game.all.to_json控制器动作.

如何将它们转换为正常的日期格式?

使用fbjs从服务器端或客户端更容易吗?fbjs有很多bug .

所以我更喜欢使用Server sideusing(Active Records)的解决方案.就像在发送JSON结构之前转换数据一样.

activerecord json ruby-on-rails

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

在java ArrayList中搜索

我正试图找出ArrayList通过其Id编号搜索客户的最佳方式.以下代码无效; 编译器告诉我,我错过了一个return声明.

Customer findCustomerByid(int id){
    boolean exist=false;

    if(this.customers.isEmpty()) {
        return null;
    }

    for(int i=0;i<this.customers.size();i++) {
        if(this.customers.get(i).getId() == id) {
            exist=true;
            break;
        }

        if(exist) {
            return this.customers.get(id);
        } else {
            return this.customers.get(id);
        }
    }

}

//the customer class is something like that
public class Customer {
    //attributes
    int id;
    int tel;
    String fname;
    String lname;
    String resgistrationDate;
}
Run Code Online (Sandbox Code Playgroud)

java search arraylist

17
推荐指数
4
解决办法
16万
查看次数

有没有办法知道ubuntu中文件的创建时间?

我正在使用ubuntu并想知道文件的创建时间,即使它被修改或访问?

linux filesystems ubuntu

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

在ubuntu上有什么插件可以在gedit上使用git吗?

我想在gedit上编码时使用git插件.我的意思是提交或快捷方式的按钮.谢谢.

git gedit

14
推荐指数
1
解决办法
5382
查看次数

红宝石面试问题

我在之前的一次采访中得到了这个问题而无法做到,任何想法?

  1. 这是做什么的:

    `$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=( 
    $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++; 
    $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++ 
    ;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=` 
    
    Run Code Online (Sandbox Code Playgroud)

ruby perl

13
推荐指数
2
解决办法
973
查看次数

比较一个对象为null!

我试图验证一个对象是否为null,我正在使用这种语法:

void renderSearch(Customer c){
         System.out.println("search customer rendering>...");
         try {
             if(!c.equals(null)){            
                 System.out.println("search customer  found...");
             }else{               
                 System.out.println("search customer not found...");
             }
         } catch (Exception e) {
             System.err.println ("search customer rendering error: "
                                     + e.getMessage()+"-"+e.getClass());
         }
     }
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

搜索客户渲染错误:null class java.lang.NullPointerException

我以为我正在用if和else循环来考虑这种可能性.任何帮助,将不胜感激.

java null object

12
推荐指数
4
解决办法
6万
查看次数

你怎么能用GIF录制你的屏幕?

在此输入图像描述

这就是我所说的例子,你怎么能这样做?

macos gif

12
推荐指数
2
解决办法
1万
查看次数

HOWTO在Ruby on rails上按平衡对项目进行排名

我正在实施一个投注系统,每个用户都有一个余额,我如何使用activerecord方法找到用户的排名?谢谢你的帮助.

ruby activerecord ruby-on-rails

11
推荐指数
3
解决办法
3366
查看次数