小编Eri*_*sma的帖子

Java SimpleDateFormat总是返回1月份的月份

我正在努力从Active Directory中获取日期值(createWhen),并将其转换为Java日期,以获取在两个日期之间创建的帐户列表.一切都工作正常,除了一种方法:从AD日期到Java日期的方法.该方法如下所示:

private Date getParsedDate(String givenString) {
    System.out.println("Value from AD is: " + givenString);
    Date parsedDate = null;
    String formattedString = this.formatDateString(givenString);
    System.out.println("Formatted String is: " + formattedString);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/DD");
    try {
        parsedDate = sdf.parse(formattedString);
        System.out.println("Final date string is: " + parsedDate.toString());
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    return parsedDate;
}
Run Code Online (Sandbox Code Playgroud)

并且,对于来自AD的单个任意数据:

Value from AD is: 20050912190509.0Z

Formatted String is: 2005/09/12

Final date string is: Wed Jan 12 00:00:00 EST 2005

显然,它正确地提取了日期和年份(如果我选择包括小时/分钟/秒,它也包括正确的那些),但是由于某种原因,每个日期都在1月份.

现在,我确定我的错误是一个非常简单的错误,但我已经重新检查了我的格式十次,而我正处于我再也看不到它的地步.第二双眼睛是否可以查看我的代码并指出我错误的地方让这个月变得非常不正确?

谢谢.

java active-directory simpledateformat

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

C++模板和子类?

所以,我正在学习C++,而且我遇到了一些我知道如何用Java做的事情,但不是用C++ :).

我有一个容器对象的模板,定义如下:

template <class T>
class Container {
    vector<T> contained;

    public:

    void add(T givenObject) {
        this->contained.push_back(givenObject);
    }

    T get(string givenIdentifier) throw (exception) {
        for (int i = 0; i < this->contained.size(); i++) {
            if (this->contained[i].getIdentifier() == givenIdentifier) {
                return this->contained[i];
            }
        }
        throw new exception("An error has occured which has caused the object you requested to not be found. Please report this bug.");
    }

    bool empty() {
        return this->contained.empty();
    }

    bool identifierExists(string givenIdentifier) {
        for (int i = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ oop interface

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

标签 统计

active-directory ×1

c++ ×1

interface ×1

java ×1

oop ×1

simpledateformat ×1