. .
CREATE OR DIE Special Downloads Shop webinale

Schauplatz

CodeSnippets

Jahreszeiten für die nördliche und südliche Hemisphere

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Verwendung

Die Jahreszeiten für die nördliche und südliche Hemisphäre sind so eine Sache und daher sollte man in der Lage sein, diese beiden Zonen voneinander zu unterscheiden. Die folgende prototype-Methode sorgt dafür, dass eine Unterscheidung zwischen den beiden Hemisphären möglich ist.

Flash MX bis Flash 8
  1. // Jahreszeiten für die nördliche und südliche Hemisphere
  2. Date.prototype.getPeriodOfYearHemisphere = function(pSphere)
  3. {
  4. var monat = this.getMonth()+1;
  5. var tag = this.getDate();
  6. if (pSphere)
  7. {
  8. // Northsphere
  9. if ((monat<3) || ((monat == 3) && (tag<20)) || ((monat == 12) && (tag>20)))
  10. {
  11. return 'Winter';
  12. }
  13. else if ((monat<6) || ((monat == 6) && (tag<21)))
  14. {
  15. return 'Frühling';
  16. }
  17. else if ((monat<9) || ((monat == 9) && (tag<23)))
  18. {
  19. return 'Sommer';
  20. }
  21. else
  22. {
  23. return 'Herbst';
  24. }
  25. }
  26. else
  27. {
  28. // Southsphere
  29. if ((monat<3) || ((monat == 3) && (tag<20)) || ((monat == 12) && (tag>20)))
  30. {
  31. return 'Sommer';
  32. }
  33. else if ((monat<6) || ((monat == 6) && (tag<21)))
  34. {
  35. return 'Herbst';
  36. }
  37. else if ((monat<9) || ((monat == 9) && (tag<23)))
  38. {
  39. return 'Winter';
  40. }
  41. else
  42. {
  43. return 'Frühling';
  44. }
  45. }
  46. };
  47. ASSetPropFlags(Date.prototype, "getPeriodNorthSouth", 1, true);
Anwendung
  1. datum = new Date();
  2. trace("Nördliche Hemisphere: " + datum.getPeriodOfYearHemisphere(true)); // North
  3. trace("Südliche Hemisphere: " + datum.getPeriodOfYearHemisphere(false)); // South

Caroline und Matthias Kannengiesser

Tags
    keine Tags
Kommentare
Bisher keine Kommentare