2017-01-02 7 views
-1

私の定式化(アンドロイドスタジオのJavaコードで)を別の日付に変更したいのですが、私の定式化を使用するにはint変数の日付(yyyy-mm-dd)が必要です(f.example i =新しい日付の結果は:aaaa/bb/cc)、 私はそれを解決するのに役立ちますか?日付(yyyy-mm-dd)をint変数に変換するには?

これらのデータをグラフに使用します。

とここに私のJavaコードです:

// generate Dates 
Calendar calendar = Calendar.getInstance(); 
Date d1 = calendar.getTime(); 
calendar.add(Calendar.DATE, 1); 
Date d2 = calendar.getTime(); 
calendar.add(Calendar.DATE, 1); 
Date d3 = calendar.getTime(); 

GraphView graph = (GraphView) findViewById(R.id.graph); 

// you can directly pass Date objects to DataPoint-Constructor 
// this will convert the Date to double via Date#getTime() 
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] { 
    new DataPoint(d1, 1), 
    new DataPoint(d2, 5), 
    new DataPoint(d3, 3) 
}); 

graph.addSeries(series); 

// set date label formatter 
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity())); 
graph.getGridLabelRenderer().setNumHorizontalLabels(3); // only 4 because of the space 

// set manual x bounds to have nice steps 
graph.getViewport().setMinX(d1.getTime()); 
graph.getViewport().setMaxX(d3.getTime()); 
graph.getViewport().setXAxisBoundsManual(true); 

// as we use dates as labels, the human rounding to nice readable numbers 
// is not necessary 
graph.getGridLabelRenderer().setHumanRounding(false); 
+0

あなたはYYYYヴァルをしたいと言っていますueはintとして、MMとddは同じですか? –

+0

変換するフォーマットにはどのようなフォーマットがありますか?すでに書かれているものはありますか? –

+0

Javaコードですか?問題のコードはhttp://www.android-graphview.org/dates-as-labels/から取得しました。それは良いスタートですが、あなたがしようとしていることを視覚化するにはかなり貧しい人です。 –

答えて

1

たぶん私はそうかもしれないあなたの質問を理解しますが、しませんでした。

私が望むのは、のint値を年、月、日のうちの特定の日付にすることです。

私に連絡して質問を明確にしてください。

とにかく、これはやり方です。

//first initialize a Calendar item. 
Calendar currentDate = Calendar.getIstance(); 
//this is the current date, you can also set up a Calendar with a custom date and time. 
//Now get the values: 
int years = currentDate.get(Calendar.YEAR); 
int months = currentDate.get(Calendar.MONTH); 
int days = currentDate.get(Calendar.DAY_OF_MONTH); 

あなたはできるもconvert a Date object to a Calendar object

参考

関連する問題