Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

HarmonyOS NEXT Development Case: Age Calculator

This article demonstrates an age calculation implementation in HarmonyOS NEXT, featuring comprehensive date information display including Gregorian/Lunar calendar conversions, zodiac signs, and astronomical statistics. Key…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Image description



This article demonstrates an age calculation implementation in HarmonyOS NEXT, featuring comprehensive date information display including Gregorian/Lunar calendar conversions, zodiac signs, and astronomical statistics.






Key Features




  • Dual calendar system support (Gregorian & Lunar)

  • Age calculation (Real age & Nominal age)

  • Zodiac and Chinese zodiac display

  • Next birthday countdown

  • Life duration statistics (months/days/hours)

  • Seasonal determination

  • Festival recognition






Implementation Overview






1. Core Data Structure






class Info {
sYear: number = 0 // Gregorian year
sMonth: number = 0 // Gregorian month
sDay: number = 0 // Gregorian day
week: number = 0 // Weekday index (0-6)
weekZH: string = "" // Weekday in Chinese
date: string = "" // Formatted date string
zodiac: string = "" // Western zodiac sign
lYear: number = 0 // Lunar year
lMonth: number = 0 // Lunar month
lDay: number = 0 // Lunar day
isLeap: boolean = false // Leap month flag
lMonthZH: string = "" // Lunar month in Chinese
lDayZH: string = "" // Lunar day in Chinese
gzYearZH: string = "" // Heavenly stem/Earthly branch year
gzMonthZH: string = "" // Heavenly stem/Earthly branch month
gzDayZH: string = "" // Heavenly stem/Earthly branch day
animal: string = "" // Chinese zodiac animal
term: string = "" // Solar term
festival: string = "" // Festival information
}









2. State Management






@Entry
@Component
struct AgeCalculatorPage {
@State season: string = '-'
@State realAge: number = 0
@State lunarAge: number = 0
@State festival: string = '-'
@State weekday: string = '-'
@State isLunar: boolean = false
@State zodiac: string = '-'
@State animal: string = '-'
@State daysToNextGregorianBirthday: number = 0
@State daysToNextLunarBirthday: number = 0
@State dayOfWeekNextGregorianBirthday: number = 0
@State dayOfWeekNextLunarBirthday: number = 0
@State totalMonthsAlive: number = 0
@State totalDaysAlive: number = 0
@State totalHoursAlive: number = 0
@State gregorianBirthDate: string = '-'
@State lunarBirthDate: string = '-'

private selectedBirthDate: Date = new Date('1989-01-17')
private weekdays: string[] = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday']
}









3. Core Algorithms






Age Calculation






private calculateRealAge(birthInfo: Info) {
const today = new Date()
let realAge = today.getFullYear() - birthInfo.sYear

if (today.getMonth() < birthInfo.sMonth - 1 ||
(today.getMonth() === birthInfo.sMonth - 1 &&
today.getDate() < birthInfo.sDay)) {
realAge--
}
this.realAge = realAge
}









Lunar Age Calculation






private calculateLunarAge() {
const today = new Date()
const lunarNewYear = new Date(today.getFullYear(), 1, 22)
let lunarAge = this.realAge + 1

if (today < lunarNewYear) {
lunarAge--
}
this.lunarAge = lunarAge
}









Life Duration Calculation






private calculateEarthTime(birthDate: Date) {
const currentDate = new Date()
const diff = currentDate.getTime() - birthDate.getTime()

this.totalMonthsAlive = Math.floor(diff / (1000 * 60 * 60 * 24 * 30.44))
this.totalDaysAlive = Math.floor(diff / (1000 * 60 * 60 * 24))
this.totalHoursAlive = Math.floor(diff / (1000 * 60 * 60))
}









4. UI Components






build() {
Column() {
Text("Age Calculator")
.width('100%')
.height(44)
.backgroundColor(Color.Orange)
.textAlign(TextAlign.Center)
.fontColor(Color.White)

Scroll() {
// UI layout implementation
// Contains multiple Row/Column components for data display
// Uses border styling and flexible layout
}

DatePicker({
start: new Date('1900-1-1'),
end: new Date('2100-1-1'),
selected: this.selectedBirthDate
})
.onDateChange((value: Date) => {
// Handle date change events
})
}
}









Technical Highlights





  1. Dual Calendar Integration




    • Utilizes calendar-tool library for lunar date conversions

    • Supports bidirectional conversion between Gregorian and Lunar dates




  2. Reactive UI




    • Uses @State decorators for automatic UI updates

    • Implements complex layout with Scroll/Row/Column components




  3. Performance Optimization




    • Memoization of date calculations

    • Efficient date difference algorithms




  4. Localization Support




    • Chinese cultural elements (Zodiac, Stems-Branches)

    • Localized date formatting








Conclusion



This implementation demonstrates HarmonyOS NEXT's capabilities in handling complex date calculations and cultural-specific requirements. The component-based architecture and reactive programming model enable efficient development of feature-rich applications.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - HarmonyOS NEXT Development Case: Age Calculator
id: f6987f7f-4acc-4073-bf4a-042b077dca03
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-27"
        description = "YARA Signature for "
    strings:
        $str = "HarmonyOS NEXT Development Cas" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("HarmonyOS NEXT Development Case Age Calc")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*HarmonyOS NEXT Development Case Age Calc*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "HarmonyOS NEXT Development Case Age Calc"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Analyse für identifizierte Bedrohung auf Basis von Live-CTI (ENISA EUVD): CVSS 0.0 · EPSS 0.0% · CISA KEV: nein. Handlungsableitung aus den verlinkten Hersteller-Quellen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten HarmonyOS NEXT Development Case: Age Calculator

Thematisch verwandte Begriffe: HarmonyOS, NEXT, Development, Case · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100739 | A vulnerability was detected in mathurvishal CloudClassroom-PHP-Project…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag