2011-07-27 2 views
3

아래에이 기능이 있습니다.C# -DateTime에 대한 Java 동등성은 무엇입니까?

다른 문자열로 만들어진 문자열과 키를 수신합니다.

이 함수는 inputs을 가져 와서 날짜를 추가하여 유효성을 검사하는 데 정확히 동일한 키를 만듭니다. 이제

public bool isSecureKeyCorrect(string inputs,string thatKey) 
{ 
    DateTime now = DateTime.UtcNow.AddHours(2); 

    string currentDateString = (now.ToString("yyyyMMddHH")); 
    string year= currentDateString.Substring(0, 4); 
    string month = currentDateString.Substring(4, 2); 
    string day = currentDateString.Substring(6, 2); 
    string hour = currentDateString.Substring(8, 2); 

    string thisKey; 



    thisKey = inputs.Substring(0, 2) + month+ hour + 
    inputs.Substring(inputs.Length - 2, 2) + year + day; 

    if (thisKey == thatKey) 
    { 
     return true; 
    } 
    else 
     return false; 


} 

, 나는 자바에서 완전한 newb 해요, 그리고 난 자바 aswell에서이 함수에 상응해야하고, 내가 자바 Date 또는 DateTime 작품, 내가 '방법에 대한 약간의 지식을 가지고 있기 때문에 누군가 코드를 적절하게 조정하는 방법을 알려줄 수 있다면 매우 행복 할 것이다.

미리 감사드립니다.

+0

이 질문에 대한 답변은 Java 설명서에서 간단히 볼 수 있습니다. 왜 우리가 너를 위해서 그런 걸 기대하니? – Sven

+0

@sven 나는 완전한 대답이 아니라, 포인터를 요구하고 있었다. 나는 총 대답을 기대하지 않았다. – doge

+0

충분히 정교합니다. :) – Sven

답변

2

조회를 해 GregorianCalendar의 방법 : 당신은 Joda-time'sDateTime을 시도 할 수 http://download.oracle.com/javase/6/docs/api/java/util/GregorianCalendar.html

+0

고마워요! 고맙게도, 나는 이런 것을 찾고있었습니다. – doge

+0

안녕하세요, 저는 자바를 배우고 있으며 "Head First Java"서적을 찾고 있습니다 (http://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208/ref=sr_1_1?ie= UTF8 & qid = 1311763851 & sr = 8-1) 매우 유익하고 유익합니다. 그것을 확인하고 싶을 수도 있습니다. – EKI

0
import java.util.Date; 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 

private String getDateTime() { 
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
    Date date = new Date(); 
    return dateFormat.format(date); 
} 
0

(설명에 자세한 사용 예를 읽을 마십시오).

관련 문제