Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Date time difference determine which is earlier Android Java example


AD MOB

Date difference in millisecond between two date, GregorianCalendar, Calendar, after(), befor(), getTimeInMillis().



public class HoriziontalScrollActivity extends Activity {
TextView txtV;
	Context cntx;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        StringBuilder strBuild = new StringBuilder();
        Calendar firstDate = new GregorianCalendar(2011, Calendar.DECEMBER, 31);
        Calendar secondDate = new GregorianCalendar(2012, Calendar.JANUARY, 1);

        
        Boolean bDetermine = firstDate.after(secondDate);            // false
        strBuild.append("Is firsDate after secondDate? " + bDetermine + "

"); bDetermine = firstDate.before(secondDate); // true strBuild.append("Is firsDate before secondDate? " + bDetermine + "
"); long differenceInMillisecond = 0L; differenceInMillisecond = secondDate.getTimeInMillis()-firstDate.getTimeInMillis(); // second == 1000 millisecond long second = differenceInMillisecond / 1000L; strBuild.append("Difference between two dates is: " + second + "
"); txtV.setText(strBuild); } }

397LW NO topic_id




AD

Další témata ....(Topics)


70

Foreach loop cycle in Java Android example | foreach-loop-cycle-in-java-android-example


Foreach in Java basic example source code.

MainClass.java


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (String s : arrayOfString)
			System.out.println(s);

	}
}

263

Eclipse failed to create the java virtual machine - Android | eclipse-failed-to-create-the-java-virtual-machine-android


Eclipse: failed to create the java virtual machine - message box

  1. Open folder with Eclipse.exe and find eclipse.ini file

  2. Replace -vmargs
    by your current real path of javaw.exe:
    -vm "c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe"




-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-product
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256M
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm "c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe” 
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-Declipse.buildId=v21.1.0-569685
282

Open Save UTF-8 File To String Java Android Code | open-save-utf-8-file-to-string-java-android-code



String sFileContent = readFile("myfile.txt",StandardCharsets.UTF_8);

	static String readFile(String path, Charset encoding) 
		  throws IOException 
		{
		  byte[] encoded = Files.readAllBytes(Paths.get(path));
		  return encoding.decode(ByteBuffer.wrap(encoded)).toString();
		}

// write file
String sOut = "text blah hello world etc.";
		writeToFile(sOut"someName.txt");	
	static void writeToFile(String sB,String name) {
		String folder = ("c:\\folder\\");
		File f = new File(folder+ name);
		BufferedWriter writer = null;
			writer = new BufferedWriter( new OutputStreamWriter(
                           new FileOutputStream( folder+name),"UTF-8"));
			writer.write( sB);

				if ( writer != null)
					writer.close( );
	}

227

Eclipse Xml Incorrect Line Endings | eclipse-xml-incorrect-line-endings


Incorrect line ending: found carriage return (\r) without corresponding newline (
)

Move mouse cursor on error text and press Ctrl+1
Select Fix line endings and press Enter

See image below:
eclipse-xml-line-ending-error

eclipse-xml-line-ending-error-1
261

Iterate over each Entry in Map Java Android | iterate-over-each-entry-in-map-java-android


entry put iterate Map HashMap Java Android

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key27", 27);
for (Map.Entry<String, Integer> entry : map.entrySet())
{
 String str = entry.getKey();
 int n = entry.getValue();
}


Editace: 2011-09-29 19:28:59
Počet článků v kategorii: 397
Url:date-time-difference-between-two-dates

AD
11 Share
Share
Tweet